PHPMVC | this is simple mvc framework 这是一个简单的phpmvc框架 | Dependency Injection library
kandi X-RAY | PHPMVC Summary
kandi X-RAY | PHPMVC Summary
在框架根目录下创建buffer缓存文件夹 并赋予777权限 Linux下需要确保 view下文件夹与控制器名称一致 |---compass 核心文件夹. $config=new Config(); $config→setPath(COMPASS.'/configs'); $config['app'];. ===========================\ #容器 通过在compass/configs/app.app配置文件中将对象绑定到容器中\ 然后在应用层通过App::get('绑定的服务名')\ 如: $app=App::get('config'); $app→config类的所有公用方法();\ 也可以通过 $app=new App(); $app→make(服务名,构造参数);. ###绑定 App::set('服务名',完整命名空间路径);\ 或则: $app=new App(); $app→bind('服务名',完整命名空间路径);. 模型 ##模型的插入方法 所有定义的模型都必须要继承compass\cores\Model基类模型\ namespace model;\ use compass\cores\Model;\. class Article extends Model { //指定数据表前置 protected $prefix='blog_'; //指定数据表名 protected $table='test'; public function index(){ //执行插入方法 $this→insert([\ 'title'⇒'test',\ 'textdesc'⇒'test',\ 'author'⇒'test',\ 'content'⇒'test',\ 'cateid'⇒1,\ ]);\ }\ }\ 模型更新操作 $this→get(10850);\ $this→title='builder';\ $this→save();\ $this→delete(108,'id'); #控制器 在控制器中继承基类控制器 use compass\cores\Controller;\ 此时可以使用$this→fetch();来渲染视图\ 如:定义控制器中的方法\ public function test(){ $this→fetch('',[ 'a'⇒'hello,world', ]); }\ 则会自动加载当前模块下的view/当前控制器名/test.html\ html代码: {$a}\ 则会输出hello,world #数据库操作 #在`compass/configs/database.php`中配置数据库的参数 connect参数\ connect($dbname=数据名, $host =主机, $username = 用户名, $password = 密码,$port=3306端口,$charset='utf8字符集')\ #使用App容器 #与数据库建立连接 App::get('db')→connect();\ 如执行更新操作:\ App::get('db')→connect('shop')→table('test')→update([ 'name'⇒'new', ],'power','name');\ 删除 删除索引id为1,2,3,4,5,6的数据并指定了表名为test,默认加载configs配置文件夹下的database.php配置文件\ App::get('db')→connect()→table('test')→delete('1,2,3,4,5,6');\ 或则:\ App::get('db')→connect()→table('test')→delete([1,2,3,4,5,6]);\ 删除掉power为1的数据\ App::get('db')→connect()→table('test')→delete(1,'power'); 返回值为返回受到影响的行数 插入 App::get('db')→connect()→table('test')→insert([ 'name'⇒'joke', 'mobile'⇒'18888888888', 'register'⇒'1970-01-01', ]); 返回值为返回受到影响的行数 查询 App::get('db')→connect()→table('test')→select();\ App::get('db')→connect()→table('test')→field('name,mobile')→select();\ App::get('db')→connect()→where('id=1')→select();\ ##更新 更改test表中id为303的字段将name改为new,mobile…\ App::get('db')→connect()→table('test')→where('id=303')→update([ 'name'⇒'new', 'mobile'⇒'1234567890' ]);\ 或则:\ App::get('db')→connect()→table('test')→update([ 'name'⇒'newd', 'mobile'⇒'1234567890' ],303,'id');\ 返回值为返回受到影响的行数. #路由 #url默认寻找路由是否注册,如果没有找到路由则会跳转到模块,控制器,方法 在compass/Route.php中定义路由\ get路由\ use compass\cores\Route;\ 此时在地址栏输入index则可以访问到index模块Index控制器index方法\ Route::get('index','index/Index/index');\ Route::post('index','index/Index/index');\. 有参路由\ Route::get('index/:id/:price','index/Index/index');\ 此时如果在地址栏输入index/1/5\ 则对应的路由为index/Index/index/id/1/price/5 post有参路由同理\.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- compile a tag
- render sub template
- clear compiled template cache
- Short description of method allocateUrl
- Do the parser
- Parse PHP source
- Executes template function
- build filepath
- Get debug variables
- Returns an array of attributes
PHPMVC Key Features
PHPMVC Examples and Code Snippets
Community Discussions
Trending Discussions on PHPMVC
QUESTION
Is it a good practice to handle all calls with one controller only ?
...ANSWER
Answered 2019-Jan-16 at 12:45A Controller
is the glue between your business logic and the requests made.
Although it can contain quite a few functionalities, they should all be specific to the target request in question.
A a small description of a controller, you will find similar cases as:
Controllers are the glue that binds models, views and other components together into a runnable application. Controllers are responsible for dealing directly with end user requests. Therefore, controllers
Understanding that, to keep your controllers focused you need to ask yourself the question: Is this functionality referred by the controller?
You can find inspiration in the laravel
way of organizing their MVC
. You will notice that they separated all authentication
requests into a AuthController
.
This AuthController
is responsible for:
-> capturing the POST
request that will contain the password and the email (or whatever other method you created).
-> Authenticate the user if successful;
-> redirect to the correct views depending on the results for auth
(back to login page or to show the dashboard);
The latest is where you have to start organizing your flow. Check this out:
-> If the user was succesfully authenticated, then you wish to present the dashboard
view;
-> the dashboard view is not really part of the AuthController
is more directly related to a DashboardController
. So, you will actually want to redirect from the AuthController
to the DashboardController
via routes
;
So the answer to your question is, it depends! If the logic you are adding to your controller is focusing on a specific business logic sector of your application, do not be bothered by the amount of methods
you might have. It all really depends of the complexity of your application;
BUT if you controller starts having methods that do many different things for many different sectors of you application, lets say you have a controller that:
QUESTION
I'm trying to make an mvc framework like ci, but I have a problem with this error. the error "Call to undefined function query()" but it's weird since query()
works fine in method getMahasiswaById()
.
Fatal error: Uncaught Error: Call to undefined function query() in C:\xampp\htdocs\phpmvc\app\models\Mahasiswa_model.php:31 Stack trace: #0 C:\xampp\htdocs\phpmvc\app\controllers\Mahasiswa.php(27): Mahasiswa_model->tambahMahasiswa(Array) #1 C:\xampp\htdocs\phpmvc\app\core\App.php(35): Mahasiswa->tambah() #2 C:\xampp\htdocs\phpmvc\public\index.php(5): App->__construct() #3 {main} thrown in C:\xampp\htdocs\phpmvc\app\models\Mahasiswa_model.php on line 31
This my model:
...
ANSWER
Answered 2018-Dec-05 at 18:27Simple syntax error:
QUESTION
i have a base twig template where i can insert body and js according to my need.Base template is like following :
...ANSWER
Answered 2017-Apr-16 at 10:28your lexxer rewrite will match your js as twig tag block
the brackets of that js object:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install PHPMVC
PHP requires the Visual C runtime (CRT). The Microsoft Visual C++ Redistributable for Visual Studio 2019 is suitable for all these PHP versions, see visualstudio.microsoft.com. You MUST download the x86 CRT for PHP x86 builds and the x64 CRT for PHP x64 builds. The CRT installer supports the /quiet and /norestart command-line switches, so you can also script it.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page