


フレームワークを推奨する投稿をいくつか読んだところですが、かなりの数の codeigniter が推奨されていますが、私の個人的な意見は参考程度に留めてください。
まず、私は codeigniter を最初にフレームワークを学び始めたときに使用しましたが、その後、会社で thinkphp を使用し、その後 2 つを使用し始めました。まず、これら 2 つのフレームワーク フォルダーの容量は比較的大きく、軽量とは言えません。
今日は codeigniter フレームワークについてだけ話します
公式 Web サイトのコントローラーがテンプレートを呼び出す例を見てみましょう
<?phpclass Blog extends CI_Controller { function index() { $data['title'] = "My Real Title"; $data['heading'] = "My Real Heading"; $this->load->view('blogview', $data); }}?>
<html><head><title><?php echo $title;?></title></head><body> <h1><?php echo $heading;?></h1></body></html>
このモデルは非常に悪いと感じます これは伝説的なコントローラー テンプレートの分離ですか?このモデルは、それを使い始めたばかりの PHPer を騙すだけです。smarty などと言って私を反論するのではなく、そのモデル自体の特徴について話しましょう。どのフレームワークも Smarty と組み合わせて使用できます。
上記のコードはPHPの関数で実装できます。extract関数の使い方を確認してください。
codeigniter を使用する多くの PHPer は、おそらく、いわゆる美しい書き方を目的としてこれを使用します。 -> ->
本質的には、テンプレート (ビュー) にはあまり影響しません。まずすべての変数が計算され、名前が変更され、必要に応じて必要な場所に新しい名前が入力されます。
そこで海外のサイトを徘徊していたら、codeigniter モデルによく似たテンプレートを発見しました。テンプレート名は不明です。テンプレートと呼んでください。これを見て、codeigniter の原理を全体的に理解することができます
そのコア テンプレート コードを書きます
<?php//template.php/** * Copyright (c) 2003 Brian E. Lozier (brian@massassi.net) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to * deal in the Software without restriction, including without limitation the * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */class Template { var $vars; /// Holds all the template variables var $path; /// Path to the templates /** * Constructor * * @param string $path the path to the templates * * @return void */ function Template($path = null) { $this->path = $path; } /** * Set the path to the template files. * * @param string $path path to template files * * @return void */ function set_path($path) { $this->path = $path; } /** * Set a template variable. * * @param string $name name of the variable to set * @param mixed $value the value of the variable * * @return void */ function set($name, $value) { $this->vars[$name] = $value; } /** * Open, parse, and return the template file. * * @param string string the template file name * * @return string */ function fetch($file) { extract($this->vars); // Extract the vars to local namespace ob_start(); // Start output buffering include($this->path . $file); // Include the file $contents = ob_get_contents(); // Get the contents of the buffer ob_end_clean(); // End buffering and discard return $contents; // Return the contents }}/** * An extension to Template that provides automatic caching of * template contents. */class CachedTemplate extends Template { var $cache_id; var $expire; var $cached; /** * Constructor. * * @param string $path path to template files * @param string $cache_id unique cache identifier * @param int $expire number of seconds the cache will live * * @return void */ function CachedTemplate($path, $cache_id = null, $expire = 900) { $this->Template($path); $this->cache_id = $cache_id ? 'cache/' . md5($cache_id) : $cache_id; $this->expire = $expire; } /** * Test to see whether the currently loaded cache_id has a valid * corrosponding cache file. * * @return bool */ function is_cached() { if($this->cached) return true; // Passed a cache_id? if(!$this->cache_id) return false; // Cache file exists? if(!file_exists($this->cache_id)) return false; // Can get the time of the file? if(!($mtime = filemtime($this->cache_id))) return false; // Cache expired? if(($mtime + $this->expire) < time()) { @unlink($this->cache_id); return false; } else { /** * Cache the results of this is_cached() call. Why? So * we don't have to double the overhead for each template. * If we didn't cache, it would be hitting the file system * twice as much (file_exists() & filemtime() [twice each]). */ $this->cached = true; return true; } } /** * This function returns a cached copy of a template (if it exists), * otherwise, it parses it as normal and caches the content. * * @param $file string the template file * * @return string */ function fetch_cache($file) { if($this->is_cached()) { $fp = @fopen($this->cache_id, 'r'); $contents = fread($fp, filesize($this->cache_id)); fclose($fp); return $contents; } else { $contents = $this->fetch($file); // Write the cache if($fp = @fopen($this->cache_id, 'w')) { fwrite($fp, $contents); fclose($fp); } else { die('Unable to write cache.'); } return $contents; } }}?>
コア テンプレート クラスでは、extract($this->vars); 関数も使用されます。配列を分割します。
彼の「コントローラー」の使い方を見てみましょう
<?php//user_list.phprequire_once('template.php');/** * This variable holds the file system path to all our template files. */$path = './templates/';/** * Create a template object for the outer template and set its variables. */$tpl = & new Template($path);$tpl->set('title', 'User List');/** * Create a template object for the inner template and set its variables. The * fetch_user_list() function simply returns an array of users. */$body = & new Template($path);$body->set('user_list', fetch_user_list());/** * Set the fetched template of the inner template to the 'body' variable in * the outer template. */$tpl->set('body', $body->fetch('user_list.tpl.php')); //这个是直接调用模板/** * Echo the results. */echo $tpl->fetch('index.tpl.php');/** * Just a function to simulate the retrieval of a user list. */function fetch_user_list() { return array( array('id' => 1, 'name' => 'bob', 'email' => 'bob@mozilla.org', 'banned' => false), array('id' => 2, 'name' => 'judy', 'email' => 'judy@php.net', 'banned' => false), array('id' => 3, 'name' => 'joe', 'email' => 'joe@opera.com', 'banned' => false), array('id' => 4, 'name' => 'billy', 'email' => 'billy@wakeside.com', 'banned' => true), array('id' => 5, 'name' => 'eileen', 'email' => 'eileen@slashdot.org', 'banned' => false));}?>
セットは割り当てです。次に、その「ビュー」がどのように出力されるかを見てください。基本的に codeigniter に似ています
//index.tpl.php<html> <head> <title><?=$title;?></title> </head> <body> <h2><?=$title;?></h2><?=$body;?> </body></html>
//user_list.tpl.php<table> <tr> <th>Id</th> <th>Name</th> <th>Email</th> <th>Banned</th> </tr><? foreach($user_list as $user): ?> <tr> <td align="center"><?=$user['id'];?></td> <td><?=$user['name'];?></td> <td><a href="mailto:<?=$user['email'];?>"><?=$user['email'];?></a></td> <td align="center"><?=($user['banned'] ? 'X' : ' ');?></td> </tr><? endforeach; ?></table>
詳細なダウンロード アドレス: http://download.csdn.net/detail/xjl756425616/3984218
ディスカッションに返信(解決策)
Copyright (c) 2003 ....10 年前! ! !
今日が4月1日だからって?
LZ はいくつかのフレームワークを推奨しています。 ~
php アンプ
Copyright (c) 2003 ....
10 年前! ! !
今日が4月1日だからって?
テクノロジーと日付の関係は何ですか? codeigniter メソッドとよく似ていると思います~
LZ はいくつかのフレームワークを推奨しています! ~
おすすめはありません~ 私はこの 2 つしか使用したことがありませんが、包括的な比較はありません。
//template.php
/*** Copyright (c) 2003 Brian E. Lozier (brian@massassi.net)
返信
codeigniter はテンプレート エンジンではありません
フレームワークはもちろん、独自のテンプレートエンジンも持っています
あなたも新しくて違うものになりたいと思いませんか?
4.1 エイプリル フール
php amp
どう思いますか?
あなたのテンプレートと CI の違いは何ですか?
結局のところ、テンプレートはob+extractではないのですか?
php amp
どう思いますか?
見ましたが、特にコメントすることはありません。そのテンプレート エンジンに似ています
CI をお勧めします。使いやすく、テンプレートはすべて同じです。 ,
実際、正しいフレームワークも間違ったフレームワークもありません。たとえば、私の会社のプロジェクトは現在緊急であり、新人は皆、使用経験がある人に非常に適しています。このフレームワークは基本的に 1 ~ 2 日で開発を開始できます ただし、限界も明らかです…
MVC は分業が細かく、コードがシンプルでわかりやすいと個人的には思います。
CI は問題なく使用しています。
php amp
どう思いますか?
見たけど、コメントすることは何もない、あのテンプレートエンジンに似てる
public function renderPhpFile($_file_, $_params_ = []) { ob_start(); ob_implicit_flush(false); extract($_params_, EXTR_OVERWRITE); require($_file_); return ob_get_clean(); }
dedecms など、eval() を使用するものもあります。 。 。 。 。 。 。 。 。 。 。 。 。

PHPは、電子商取引、コンテンツ管理システム、API開発で広く使用されています。 1)eコマース:ショッピングカート機能と支払い処理に使用。 2)コンテンツ管理システム:動的コンテンツの生成とユーザー管理に使用されます。 3)API開発:RESTFUL API開発とAPIセキュリティに使用されます。パフォーマンスの最適化とベストプラクティスを通じて、PHPアプリケーションの効率と保守性が向上します。

PHPにより、インタラクティブなWebコンテンツを簡単に作成できます。 1)HTMLを埋め込んでコンテンツを動的に生成し、ユーザー入力またはデータベースデータに基づいてリアルタイムで表示します。 2)プロセスフォームの提出と動的出力を生成して、XSSを防ぐためにHTMLSPECIALCHARSを使用していることを確認します。 3)MySQLを使用してユーザー登録システムを作成し、Password_HashおよびPreprocessingステートメントを使用してセキュリティを強化します。これらの手法を習得すると、Web開発の効率が向上します。

PHPとPythonにはそれぞれ独自の利点があり、プロジェクトの要件に従って選択します。 1.PHPは、特にWebサイトの迅速な開発とメンテナンスに適しています。 2。Pythonは、データサイエンス、機械学習、人工知能に適しており、簡潔な構文を備えており、初心者に適しています。

PHPは依然として動的であり、現代のプログラミングの分野で重要な位置を占めています。 1)PHPのシンプルさと強力なコミュニティサポートにより、Web開発で広く使用されています。 2)その柔軟性と安定性により、Webフォーム、データベース操作、ファイル処理の処理において顕著になります。 3)PHPは、初心者や経験豊富な開発者に適した、常に進化し、最適化しています。

PHPは、現代のWeb開発、特にコンテンツ管理とeコマースプラットフォームで依然として重要です。 1)PHPには、LaravelやSymfonyなどの豊富なエコシステムと強力なフレームワークサポートがあります。 2)パフォーマンスの最適化は、Opcacheとnginxを通じて達成できます。 3)PHP8.0は、パフォーマンスを改善するためにJITコンパイラを導入します。 4)クラウドネイティブアプリケーションは、DockerおよびKubernetesを介して展開され、柔軟性とスケーラビリティを向上させます。

PHPは、特に迅速な開発や動的なコンテンツの処理に適していますが、データサイエンスとエンタープライズレベルのアプリケーションには良くありません。 Pythonと比較して、PHPはWeb開発においてより多くの利点がありますが、データサイエンスの分野ではPythonほど良くありません。 Javaと比較して、PHPはエンタープライズレベルのアプリケーションでより悪化しますが、Web開発により柔軟性があります。 JavaScriptと比較して、PHPはバックエンド開発により簡潔ですが、フロントエンド開発のJavaScriptほど良くありません。

PHPとPythonにはそれぞれ独自の利点があり、さまざまなシナリオに適しています。 1.PHPはWeb開発に適しており、組み込みのWebサーバーとRich Functionライブラリを提供します。 2。Pythonは、簡潔な構文と強力な標準ライブラリを備えたデータサイエンスと機械学習に適しています。選択するときは、プロジェクトの要件に基づいて決定する必要があります。

PHPは、サーバー側で広く使用されているスクリプト言語で、特にWeb開発に適しています。 1.PHPは、HTMLを埋め込み、HTTP要求と応答を処理し、さまざまなデータベースをサポートできます。 2.PHPは、ダイナミックWebコンテンツ、プロセスフォームデータ、アクセスデータベースなどを生成するために使用され、強力なコミュニティサポートとオープンソースリソースを備えています。 3。PHPは解釈された言語であり、実行プロセスには語彙分析、文法分析、編集、実行が含まれます。 4.PHPは、ユーザー登録システムなどの高度なアプリケーションについてMySQLと組み合わせることができます。 5。PHPをデバッグするときは、error_reporting()やvar_dump()などの関数を使用できます。 6. PHPコードを最適化して、キャッシュメカニズムを使用し、データベースクエリを最適化し、組み込み関数を使用します。 7


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

SecLists
SecLists は、セキュリティ テスターの究極の相棒です。これは、セキュリティ評価中に頻繁に使用されるさまざまな種類のリストを 1 か所にまとめたものです。 SecLists は、セキュリティ テスターが必要とする可能性のあるすべてのリストを便利に提供することで、セキュリティ テストをより効率的かつ生産的にするのに役立ちます。リストの種類には、ユーザー名、パスワード、URL、ファジング ペイロード、機密データ パターン、Web シェルなどが含まれます。テスターはこのリポジトリを新しいテスト マシンにプルするだけで、必要なあらゆる種類のリストにアクセスできるようになります。

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

AtomエディタMac版ダウンロード
最も人気のあるオープンソースエディター

PhpStorm Mac バージョン
最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)
