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.
        
        
        
        
        
        
        
        
        
     
        
       

  • 相关阅读:
    window执行python文件
    百钱买百鸡
    牛的数量有多少
    如何实现杨辉三角
    怎样求解斐波那契数列
    php快速做外包后台开源产品
    如何实现洗牌算法
    如何获取规定的排列组合
    怎样才能得到阿姆斯壮数
    如何利用约瑟夫环来保护你与你的朋友
  • 原文地址:https://www.cnblogs.com/shuman/p/5478175.html
Copyright © 2011-2022 走看看