zoukankan      html  css  js  c++  java
  • [Phalcon-framework] Phalcon framework

    Registering services in the Container

    - We can easily replace a component with one created by ourselves or a third party.
    - We have full control of the object initialization, allowing us to set these objects, as needed before delivering them to components.
    - We can get global instances of components in a structured and unified way.

    Services can be registered using serverial types of definitions:

    <?php

        use PhalconHttpRequest;
        // Create the Dependency Injector Container
        $di = new PhalconDi();
        // By its class name
        $di->set("request", "PhalconHttpRequest");
        
        // Using an anonymous function, the instance will be lazy loaded
        $di->set("request", function () {
            return new Request();
        });
        
        // Regsitering an instance directly
        $di->set("request", new Request());
        
        // Using an array definition
        $di->set(
            "request",
            array(
                "className" => 'PhalconHttpRequest'
            )
        );
     
    <?php
     
     // The array syntax is also allowed to register service:
        
        use PhalconHttpRequest;
        // Create the Dependency Injector Container
        $di = new PhalconDi();
        
        // By its class name
        $di['request'] = 'PhalconHttpRequest';
        // Using an anonymous function, the instance will be lazy loaded
        $di['request'] = function () {
            return new Request();
        };
        
        // Registering an instance directly
        $di["request"] = new Request();
        
        // Using an array definition
        $di['request'] = array(
            "className" => 'PhalconHttpRequest'
        );
        
        
    Models
        
        A model represents the information (data) of the application and the rules to manipulate that data. Models are primaryly used for managing the rules of interaction with a corresponding database table. In most cases, each table in your database will correspond to one model in your application. The bulk of your application's business logic will be concentrated in the models.
        
    Views
        
        view represent the user interface of your applicaiton. Views are often HTML files with embeded PHP coe that perform tasks related solely to the presentation of the data. Views handle the job of providing data to the web browser or other tool that is used to make requests from your application.
        
     Controllers
     
        The controllers provide the "flow" between models and views. Controllers are responsible for processing the incoming requests from the web browser, interrogating the models for data, and passing that data on to the views for presentation.
        
        
        
        
        
        
        
        
        
     
        
       

  • 相关阅读:
    ThinkPHP部署
    Linux下的vim常用操作
    Linux常用命令
    PHP中常用操作文件的方法
    PHP中的错误处理机制
    06 webpack4.0学习笔记——配置文件_sass-loader使用
    05 webpack4.0学习笔记——配置文件_babel-loader使用
    04 webpack4.0学习笔记——配置文件_url-loader使用
    03 webpack4.0学习笔记——配置文件_入口出口
    02 webpack4.0学习笔记——安装、基本命令
  • 原文地址:https://www.cnblogs.com/shuman/p/5478175.html
Copyright © 2011-2022 走看看