Showing posts with label Symfony. Show all posts
Showing posts with label Symfony. Show all posts

Jul 25, 2012

Symfony - Logger Setting and Enable

Enable File apps/YOUR_APP/config/factories.yml
prod:
  logger:
   class: sfNoLogger     param:
     level: err
     loggers: ~
to
prod:
  logger:
   class: sfFileLogger
    param:
     level: debug
     loggers: ~
     file: %SF_LOG_DIR%/%SF_APP%_%SF_ENVIRONMENT%.log
Enable symfony debugging apps/YOUR_APP/config/setting.yml
prod:
  .settings:
   no_script_name: true
   logging_enabled: false # Please change to "true"

Reference: Ticket
Application-Management-Tools

Jun 4, 2012

Symfony: Get Module Name and Action Name

Get Module or Action name all over the code

sfContext::getInstance()->getModuleName()
sfContext::getInstance()->getActionName()

Get Module or Action name in you action file

$this->getModuleName()
$this->getActionName()

Get Module or Action name in template file

$sf_context->getModuleName()
$sf_context->getModuleName()

May 24, 2012

Symfony - Disable sf_web_debug in your web page

In our development environment, there some way we need to programmaticall disable the Web Debug. In some instance like we are retrieving text data on out controller.
  public function executeGetText(sfWebRequest $request)
  {
     sfConfig::set('sf_web_debug', false); // Here to disable web debug only and hase html response
     // Some code here.. Good luck =)
  }
You can also do this one, this will return you the plain text.
  public function executeGetText(sfWebRequest $request)
  {
     $this->getResponse()->setHttpHeader('Content-type', 'text/plain', true);
     // Some code here.. Good luck =)
  }

Sep 14, 2011

Symfony: Propel Custom Join

NOTE:
In Didn't try this yet. May I update this page after I test in my self too. Thsi will serve a reference for the mentime.

References
ApplyingCustomJoinsInDoSelect

Symfony: Propel Custom Query

Here's sample Code

$connection = Propel::getConnection();
$query = 'SELECT MAX(?) AS max FROM ?';
$statement = $connection->prepareStatement($query);
$statement->setString(1, ArticlePeer::CREATED_AT);
$statement->setString(2, ArticlePeer::TABLE_NAME);
$resultset = $statement->executeQuery();
$resultset->next();
$max = $resultset->getInt('max')


Reference
08-Inside-the-Model-Layer

Jul 6, 2011

Symfony: Create project


php symfony/data/bin/symfony generate:project PROJECT_NAME --orm=Propel

php symfony configure:database "mysql:host=localhost;dbname=DB_NAME" DB_USER DB_PASS

php symfony generate:app frontend

symfony propel:generate-module --with-show --non-verbose-templates frontend registration Registration

Jun 27, 2011

Symfony/Zend: Download Attach File in the Action Controller.

Synfony


public function executeDownload(sfWebRequest $request)  
{  
$response = $this->getContext()->getResponse();  
$response->clearHttpHeaders();  
$response->addCacheControlHttpHeader('Cache-control','must-revalidate, post-check=0, pre-check=0');  
$response->setContentType('application/octet-stream',TRUE);      
$response->setHttpHeader('Content-Transfer-Encoding', 'binary', TRUE);  
$response->setHttpHeader('Content-Disposition','attachment; filename='.$request->getParameter('filename'), TRUE);  
$response->sendHttpHeaders(); // Need to send the HttpHeaders to handle a large file size
readfile(readfile('xxx.mp3'));  
return sfView::NONE;  
}

* Always dont omit the line to send the headers

Zend


$this->getResponse()->setHeader("Pragma","public");
$this->getResponse()->setHeader("Expires", "0");
$this->getResponse()->setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
$this->getResponse()->setHeader("Cache-Control","private", false);
$this->getResponse()->setHeader("Content-Type","audio/x-mp3");
$this->getResponse()->setHeader("Content-Disposition","attachment; filename=\"xxx.mp3\"");
$this->getResponse()->setHeader("Content-Transfer-Encoding","binary");
$this->getResponse()->setHeader("Content-Length", filesize('xxx.mp3'));
$this->getResponse()->setHeader("Content-Description","File Transfer");
$this->getResponse()->sendHeaders(); // Need to send the HttpHeaders to handle a large file size
$this->getResponse()->setBody(readfile('xxx.mp3'));

Aug 10, 2010

Rewrite symfony URL

Setting the virtual host:

<VirtualHost *:80>
ServerName admin.my-app.com
DirectoryIndex backend.php
DocumentRoot "/path/to/the/web/directory"
<Directory "/path/to/the/web/directory">
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
Alias /sf /path/to/the/symfony/data/web/sf
<Directory "/path/to/the/symfony/data/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>


Setting the .htaccess

Options +FollowSymLinks +ExecCGI



RewriteEngine On

## uncomment the following line, if you are having trouble
## getting no_script_name to work
RewriteBase /

## we skip all files with .something
##RewriteCond %{REQUEST_URI} \..+$
##RewriteCond %{REQUEST_URI} !\.html$
##RewriteRule .* - [L]

## we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f

## no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]

## Just search in the Net
## The admin subdomain returns to the backend
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{HTTP_HOST} ^admin\.my-app\..*
#RewriteRule ^(.*)$ backend.php [QSA,L]

#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{HTTP_HOST} ^admin\.my-app\..*
#RewriteRule ^(.*)$ index.php [QSA,L]



Try to access like


http://host.com/module/action

The common to access is

http://host.com/index.php/module/action


Reference URL