<?php
define('SF_ROOT_DIR', realpath(dirname(__FILE__).'/..'));
define('SF_APP', 'myapp');
define('SF_ENVIRONMENT', 'prod');
define('SF_DEBUG', false);
require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');
sfContext::getInstance()->getController()->dispatch();
## app.yml staging: mail: webmaster: dummy@mysite.com contact: dummy@mysite.com all: mail: webmaster: webmaster@mysite.com contact: contact@mysite.com ##查看结果 http://localhost/myapp_staging.php/mymodule/index
<?php
define('SF_ROOT_DIR', realpath(dirname(__FILE__).'/..'));
define('SF_APP', 'myapp');
define('SF_ENVIRONMENT', 'prod');
define('SF_DEBUG', false);
require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');
// 添加批处理代码
<?php
define('SF_ROOT_DIR', realpath(dirname(__FILE__).'/..'));
define('SF_APP', 'myapp');
define('SF_ENVIRONMENT', 'prod');
define('SF_DEBUG', false);
require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');
class mymoduleActions extends sfActions
{
public function executeIndex()
{
// Retrieving request parameters
$password = $this->getRequestParameter('password');
// Retrieving controller information
$moduleName = $this->getModuleName();
$actionName = $this->getActionName();
// Retrieving framework core objects
$request = $this->getRequest();
$userSession = $this->getUser();
$response = $this->getResponse();
$controller = $this->getController();
$context = $this->getContext();
// Setting action variables to pass information to the template
$this->setVar('foo', 'bar');
$this->foo = 'bar'; // Shorter version
}
}
return sfView::SUCCESS;
# 将调用indexSuccess.php模板
public function executeIndex()
{
return sfView::SUCCESS;
}
# 将调用listSuccess.php模板
public function executeList()
{
}
# symfony将查找actionNameError.php模板 return sfView::ERROR;
# symfony将查找actionNameMyResult.php模板 return 'MyResult';
return sfView::NONE;
public function executeIndex()
{
echo "<html><body>Hello, World!</body></html>";
return sfView::NONE;
}
// 等价方法
public function executeIndex()
{
return $this->renderText("<html><body>Hello, World!</body></html>");
}
public function executeRefresh()
{
$output = '<"title","My basic letter"],["name","Mr Brown">';
$this->getResponse()->setHttpHeader("X-JSON", '('.$output.')');
return sfView::HEADER_ONLY;
}
$this->setTemplate('myCustomTemplate');
$this->forward('otherModule','otherAction');
$this->redirect('otherModule/otherAction');
$this->redirect('http://www.google.cn');
public function executeShow()
{
$article = ArticlePeer::retrieveByPK($this->getRequestParameter('id'));
$this->forward404If(!$article);
}
public function executeShow()
{
$article = ArticlePeer::retrieveByPK($this->getRequestParameter('id'));
$this->forward404Unless($article);
}
class mymoduleActions extends sfActions
{
public function preExecute()
{
// 这里的代码在每一个动作调用之前执行
...
}
public function executeIndex()
{
...
}
public function executeList()
{
...
$this->myCustomMethod(); // 调用自定义的方法
}
public function postExecute()
{
// 这里的代码会在每个动作结束后执行
...
}
protected function myCustomMethod()
{
// 添加自己的方法,虽然他们没有以execute开头
// 在这里,最好将方法定义为protected(保护的)或者private(私有的)
...
}
}
|
[b]方法名[/b]
|
[b]功能[/b]
|
[b]输入示例[/b]
|
|
[b]Request Information[/b]
|
|
|
|
getMethod()
|
Request对象
|
Returns sfRequest::GET or sfRequest::POST constants
|
|
getMethodName()
|
Request对象名
|
'POST'
|
|
getHttpHeader('Server')
|
给定HTTP头的值
|
'Apache/2.0.59 (Unix) DAV/2 PHP/5.1.6'
|
|
getCookie('foo')
|
指定名称Cookie的值
|
'bar'
|
|
isXmlHttpRequest()*
|
是否是AJAX请求?
|
true
|
|
isSecure()
|
是否是SSL请求
|
true
|
|
[b]Request Parameters[/b]
|
|
|
|
hasParameter('foo')
|
参数是否在请求中有
|
true
|
|
getParameter('foo')
|
指定参数的值
|
'bar'
|
|
getParameterHolder()->getAll()
|
所有请求参数的数组
|
|
|
[b]URI-Related Information[/b]
|
|
|
|
getUri()
|
完整URI
|
'http://localhost/myapp_dev.php/mymodule/myaction'
|
|
getPathInfo()
|
路径信息
|
'/mymodule/myaction'
|
|
getReferer()**
|
来自那里?
|
'http://localhost/myapp_dev.php/'
|
|
getHost()
|
主机名
|
'localhost'
|
|
getScriptName()
|
前端控制器路径与名称
|
'myapp_dev.php'
|
|
[b]Client Browser Information[/b]
|
|
|
|
getLanguages()
|
可接受语言的列表
|
Array( [0] => fr [1] => fr_FR [2] => en_US [3] => en )
|
|
getCharsets()
|
可接受字符集的列表
|
Array( [0] => ISO-8859-1 [1] => UTF-8 [2] => * )
|
|
getAcceptableContentTypes()
|
可接受内容类型数组
|
|
class mymoduleActions extends sfActions
{
public function executeIndex()
{
$hasFoo = $this->getRequest()->hasParameter('foo');
$hasFoo = $this->hasRequestParameter('foo'); // Shorter version
$foo = $this->getRequest()->getParameter('foo');
$foo = $this->getRequestParameter('foo'); // Shorter version
}
}
class mymoduleActions extends sfActions
{
public function executeUpload()
{
if ($this->getRequest()->hasFiles())
{
foreach ($this->getRequest()->getFileNames() as $fileName)
{
$fileSize = $this->getRequest()->getFileSize($fileName);
$fileType = $this->getRequest()->getFileType($fileName);
$fileError = $this->getRequest()->hasFileError($fileName);
$uploadDir = sfConfig::get('sf_upload_dir');
$this->getRequest()->moveFile('file', $uploadDir.'/'.$fileName);
}
}
}
}
class mymoduleActions extends sfActions
{
public function executeFirstPage()
{
$nickname = $this->getRequestParameter('nickname');
// Store data in the user session
$this->getUser()->setAttribute('nickname', $nickname);
}
public function executeSecondPage()
{
// Retrieve data from the user session with a default value
$nickname = $this->getUser()->getAttribute('nickname', 'Anonymous Coward');
}
}
class mymoduleActions extends sfActions
{
public function executeRemoveNickname()
{
$this->getUser()->getAttributeHolder()->remove('nickname');
}
public function executeCleanup()
{
$this->getUser()->getAttributeHolder()->clear();
}
}
<p>
Hello, <?php echo $sf_user->getAttribute('nickname') ?>
</p>
$this->setFlash('attrib', $value);
$value = $this->getFlash('attrib');
<?php if ($sf_flash->has('attrib')): ?>
<?php echo $sf_flash->get('attrib') ?>
<?php endif; ?>
<?php echo $sf_flash->get('attrib') ?>
all: storage: class: sfSessionStorage param: session_name: 自定义Cookie名字
all: storage: class: sfMySQLSessionStorage param: db_table: SESSION_TABLE_NAME # 存储Session的表 database: DATABASE_CONNECTION # 数据库的名称 Class名称可以是:fMySQLSessionStorage, sfPostgreSQLSessionStorage和sfPDOSessionStorage;后面是首选方式。 Session超时的修改和调整:apps/myapp/config/settings.yml default: .settings: timeout: 1800 #Session超时 单位秒
read: is_secure: off # 所有用户都可以请求Read动作 update: is_secure: on # update动作只能有认证的用户访问 delete: is_secure: on # 同update credentials: admin # 具有admin凭证 all: is_secure: off # 无需授权
all: .actions: login_module: default login_action: login secure_module: default secure_action: secure
class myAccountActions extends sfActions
{
public function executeLogin()
{
if ($this->getRequestParameter('login') == 'foobar') //判断根据具体需求而定
{
$this->getUser()->setAuthenticated(true); //设置用户为已认证
}
}
public function executeLogout()
{
$this->getUser()->setAuthenticated(false); //设置用户为未认证
}
}
class myAccountActions extends sfActions
{
public function executeDoThingsWithCredentials()
{
$user = $this->getUser();
// 添加凭证
$user->addCredential('foo');
$user->addCredentials('foo', 'admin'); //添加多个凭证
// 判断是否具有凭证
echo $user->hasCredential('foo'); => true
// 判断是否具有多个凭证
echo $user->hasCredential(array('foo', 'admin')); => true
// Check if the user has one of the credentials
echo $user->hasCredential(array('foo', 'admin'), false); => true
// 删除凭证
$user->removeCredential('foo');
echo $user->hasCredential('foo'); => false
// 删除所有凭证 (被用在注销处理过程中)
$user->clearCredentials();
echo $user->hasCredential('admin'); => false
}
}
<ul>
<li><?php echo link_to('section1', 'content/section1') ?></li>
<li><?php echo link_to('section2', 'content/section2') ?></li>
<?php if ($sf_user->hasCredential('section3')): ?>
<li><?php echo link_to('section3', 'content/section3') ?></li>
<?php endif; ?>
</ul>
editArticle: credentials: [ admin, editor ] # admin 和 editor publishArticle: credentials: [ admin, publisher ] # admin 和 publisher userManagement: credentials: [[ admin, superuser ]] # admin 或者 superuser
credentials: [[root, [supplier, [owner, quasiowner]], accounts]]
# root 或者 (supplier 和 (owner 或者 quasiowner)) 或者 accounts
class mymoduleActions extends sfActions
{
public function validateMyAction()
{
return ($this->getRequestParameter('id') > 0);
}
public function handleErrorMyAction()
{
$this->message = "Invalid parameters";
return sfView::SUCCESS;
}
public function executeMyAction()
{
$this->message = "The parameters are correct";
}
}
class myFilter extends sfFilter
{
public function execute ($filterChain)
{
// 在动作之前执行的代码
...
// 执行下一个过滤器
$filterChain->execute();
// 在动作之后执行的代码
...
}
}
rendering: ~ web_debug: ~ security: ~ # 在这里插入你自己的过滤器 cache: ~ common: ~ flash: ~ execution: ~
Web_debug: enabled: off
class rememberFilter extends sfFilter
{
public function execute($filterChain)
{
// 通过调用isFirstCall方法保证只执行一次
if ($this->isFirstCall())
{
// 过滤器不直接访问请求和用户对象,你需要使用context对象获取
// You will need to use the context object to get them
$request = $this->getContext()->getRequest();
$user = $this->getContext()->getUser();
if ($request->getCookie('MyWebSite'))
{
// 登入
$user->setAuthenticated(true);
}
}
// 执行下一个过滤器
$filterChain->execute();
}
}
return $this->getContext()->getController()->forward('mymodule', 'myAction');
rendering: ~ web_debug: ~ security: ~ remember: # Filters need a unique name class: rememberFilter param: cookie_name: MyWebSite condition: %APP_ENABLE_REMEMBER_ME% cache: ~ common: ~ flash: ~ execution: ~
class rememberFilter extends sfFilter
{
public function execute ($filterChain)
{
...
if ($request->getCookie($this->getParameter('cookie_name')))
...
}
}
all: enable_remember_me: on
class sfGoogleAnalyticsFilter extends sfFilter
{
public function execute($filterChain)
{
// 在动作之前什么也不做
$filterChain->execute();
// 使用下面的代码修饰响应
$googleCode = '
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct="UA-'.$this->getParameter('google_id').'";urchinTracker();
</script>';
$response = $this->getContext()->getResponse();
$response->setContent(str_ireplace('</body>', $googleCode.'</body>',$response->getContent()));
}
}
class sfSecureFilter extends sfFilter
{
public function execute($filterChain)
{
$context = $this->getContext();
$request = $context->getRequest();
if (!$request->isSecure())
{
$secure_url = str_replace('http', 'https', $request->getUri());
return $context->getController()->redirect($secure_url);
// We don't continue the filter chain
}
else
{
// The request is already secure, so we can continue
$filterChain->execute();
}
}
}
all: #对所有环境 enabled: true is_internal: false view_name: sfPHP
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有