码迷,mamicode.com
首页 > 其他好文 > 详细

phalcon学习

时间:2016-08-10 19:20:05      阅读:694      评论:0      收藏:0      [点我收藏+]

标签:

<?php 
安装篇幅:
[root@www ~]#wget https://github.com/phalcon/cphalcon.git 
//解压后一定要跑到build目录下  phpize 生成configure文件  本人在此处遇坑,一直找不到config.m4文件
[root@www ~]#cd cphalcon-master/build/ 
[root@www ~]#phpize 
[root@www ~]#./configure --with-config=/usr/local/php/bin/php-config
[root@www ~]#make && make install
 

目录 
|++ app             应用目录
|   |++ controllers 控制器
|   |++ models      模型
|   |++ views       视图
|   |++ cache       模板缓存文件; 
|   |++ config      配置
|        |++  config.php
|        |++  loader.php
|        |++  routes.php
|        |++  service.php 
|++ public      入口文件目录 
|   |++ index.php 

 
  
 
入口 index.php
    $debug = new \Phalcon\Debug();
    $debug->listen();  
	
	$config = include __DIR__ . "/../apps/config/config.php";
	  
	include __DIR__ . "/../apps/config/loader.php";
	 
	include __DIR__ . "/../apps/config/services.php";
	 
	class BaseApplication extends \Phalcon\Mvc\Application
	{
	    
	}  
	$application = new BaseApplication(); 
	$application->setDI($di); 
	echo $application->handle()->getContent();
	 
 
    
   
//注册一个路由器层 
$di ->set(‘router‘, function() {
    $router = new \Phalcon\Mvc\Router();
   //nginx的rewrite 这句非常重要 不然只能访问index控制器index方法 本人在此与坑
    $router->setUriSource(\Phalcon\Mvc\Router::URI_SOURCE_SERVER_REQUEST_URI);
 
    //Define a route
    $router->add(
        "/admin/:controller/a/:action/:params",
        array( "controller" => 1, //匹配第一个占位符(/:controller)
            "action"     => 2, //匹配第二个占位符(/:action)
            "params"     => 3, //匹配第三个占位符(/:params)
        ) );
      
    $router->add(
        "/news/([0-9]{4})/([0-9]{2})/([0-9]{2})/:params",
        array(
            "controller" => "index",
            "action" => "show",
            "year"   => 1, // ([0-9]{4})
            "month"  => 2, // ([0-9]{2})
            "day"=> 3, // ([0-9]{2})
            "params" => 4, // :params
        )
    )->convert(‘params‘, function($params) {
        //Transform the slug removing the dashes
        return str_replace(‘-‘, ‘‘, $params);
    });
    
    $router->setDefaultController(‘index‘);
    $router->setDefaultAction(‘index‘);
    
    //Using an array
    $router->setDefaults(array(
        ‘controller‘ => ‘index‘,
        ‘action‘     => ‘index‘
    ));
    return $router;
});


 
控制器
class IndexController extends ControllerBase
{
    //所有方法之前执行
    public function beforeExecuteRoute($dispatcher)
    { 
          echo "<br/>";
    }
	
	//先执行 beforeExecuteRoute方法  在执行  initialize方法
    public function initialize() 
	{
		
	}
	
	 public function showAction()
     {
		$post = $this->request->getPost(); //接收所有post参数
        $robot = MgUserMember::findFirst()->toArray();
        print_r($robot);
        echo $this->view->hello = "hey, hello!";
      
	 
       $this->view->setVar("name", $robot->nickname); //传值到视图
	   
	    $this->view->disable(); //关闭视图
		 
		 $this->view->pick("layouts/test"); //选择视图文件
        $this->view->pick("index/index");  //默认会自动渲染此文件
    }
	
	
	//所有方法之后执行
    public function afterExecuteRoute($dispatcher)
    {
		 $this->dispatcher->forward(array(
            ‘controller‘ => ‘home‘,
            ‘action‘     => ‘index‘
        ));
	}
}
	




模型层 
use Phalcon\Mvc\Model;

class MgUserMember extends Model {
    
    public function initialize() { 
        $this->setReadConnectionService(‘dbRead‘); 
    }
    
    
    public function getSource()  //返回表名
    {
        return ‘mg_user_member‘;
    }
}



视图层 
<html>
<head>
  <title>问我我我我我娃娃</title>
</head>
<body>
       <h1>aaaaaaaaaa</h1>
       <?php echo $this->getContent() ?>
</body>
</html>
















//常用类
 print_r(get_class_methods($this->request)); 
    [0] => getHttpMethodParameterOverride
    [1] => setHttpMethodParameterOverride
    [2] => setDI
    [3] => getDI
    [4] => get
    [5] => getPost
    [6] => getPut
    [7] => getQuery
    [8] => getServer
    [9] => has
    [10] => hasPost
    [11] => hasPut
    [12] => hasQuery
    [13] => hasServer
    [14] => getHeader
    [15] => getScheme
    [16] => isAjax
    [17] => isSoap
    [18] => isSoapRequested
    [19] => isSecure
    [20] => isSecureRequest
    [21] => getRawBody
    [22] => getJsonRawBody
    [23] => getServerAddress
    [24] => getServerName
    [25] => getHttpHost
    [26] => setStrictHostCheck
    [27] => isStrictHostCheck
    [28] => getPort
    [29] => getURI
    [30] => getClientAddress
    [31] => getMethod
    [32] => getUserAgent
    [33] => isValidHttpMethod
    [34] => isMethod
    [35] => isPost
    [36] => isGet
    [37] => isPut
    [38] => isPatch
    [39] => isHead
    [40] => isDelete
    [41] => isOptions
    [42] => isPurge
    [43] => isTrace
    [44] => isConnect
    [45] => hasFiles
    [46] => getUploadedFiles
    [47] => getHeaders
    [48] => getHTTPReferer
    [49] => getContentType
    [50] => getAcceptableContent
    [51] => getBestAccept
    [52] => getClientCharsets
    [53] => getBestCharset
    [54] => getLanguages
    [55] => getBestLanguage
    [56] => getBasicAuth
    [57] => getDigestAuth


	
	
	
	
	
	
  print_r(get_class_methods($this->response));
    [0] => __construct
    [1] => setDI
    [2] => getDI
    [3] => setStatusCode
    [4] => getStatusCode
    [5] => setHeaders
    [6] => getHeaders
    [7] => setCookies
    [8] => getCookies
    [9] => setHeader
    [10] => setRawHeader
    [11] => resetHeaders
    [12] => setExpires
    [13] => setLastModified
    [14] => setCache
    [15] => setNotModified
    [16] => setContentType
    [17] => setContentLength
    [18] => setEtag
    [19] => redirect
    [20] => setContent
    [21] => setJsonContent
    [22] => appendContent
    [23] => getContent
    [24] => isSent
    [25] => sendHeaders
    [26] => sendCookies
    [27] => send
    [28] => setFileToSend
	
	
	
	
	
	
	
	
	
	
	
 print_r(get_class_methods($this->view));
    [0] => getRenderLevel
    [1] => getCurrentRenderLevel
    [2] => getRegisteredEngines
    [3] => __construct
    [4] => setViewsDir
    [5] => getViewsDir
    [6] => setLayoutsDir
    [7] => getLayoutsDir
    [8] => setPartialsDir
    [9] => getPartialsDir
    [10] => setBasePath
    [11] => getBasePath
    [12] => setRenderLevel
    [13] => disableLevel
    [14] => setMainView
    [15] => getMainView
    [16] => setLayout
    [17] => getLayout
    [18] => setTemplateBefore
    [19] => cleanTemplateBefore
    [20] => setTemplateAfter
    [21] => cleanTemplateAfter
    [22] => setParamToView
    [23] => setVars
    [24] => setVar
    [25] => getVar
    [26] => getParamsToView
    [27] => getControllerName
    [28] => getActionName
    [29] => getParams
    [30] => start
    [31] => registerEngines
    [32] => exists
    [33] => render
    [34] => pick
    [35] => getPartial
    [36] => partial
    [37] => getRender
    [38] => finish
    [39] => isCaching
    [40] => getCache
    [41] => cache
    [42] => setContent
    [43] => getContent
    [44] => getActiveRenderPath
    [45] => disable
    [46] => enable
    [47] => reset
    [48] => __set
    [49] => __get
    [50] => isDisabled
    [51] => __isset
    [52] => setDI
    [53] => getDI
    [54] => setEventsManager
    [55] => getEventsManager
	
	
	
	 












 



 

 

phalcon学习

标签:

原文地址:http://www.cnblogs.com/sixiong/p/5757911.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!