Skip to content

Instantly share code, notes, and snippets.

View Narven's full-sized avatar
👾
Walking to the fridge...

Pedro Luz Narven

👾
Walking to the fridge...
View GitHub Profile
@Narven
Narven / main.php
Created November 26, 2013 21:36 — forked from jamband/main.php
<?php
return array(
'components' => array(
...
'viewRenderer' => array(
'class' => 'ext.ETwigViewRenderer',
'globals' => array(
'Yii' => 'Yii',
'Captcha' => 'CCaptcha',
),
@Narven
Narven / yii_zend_mail_options
Created November 27, 2013 14:44
Send emails in Yii with Zend Mail (local e production)
$smtpConfig = array(
'ssl' => 'ssl',
'port' => '465',
'auth' => 'login',
'username' => '[email protected]',
'password' => 'password'
);
// default
//$oTransport = new Zend_Mail_Transport_Smtp(); // @TODO enable for production
@Narven
Narven / error_log_to_email.php
Created December 16, 2013 14:41
send error log messages to specific email
error_log("MSG", 1, "[email protected]","From: [email protected]");
@Narven
Narven / yii_model_custom_rules
Last active January 2, 2016 22:19
Yii Model Custom Rules
<?php
// rule for date format
array('birth_date', 'date', 'format'=>'yyyy-mm-dd', 'message'=>'Birth Date, wrong format. Must be YYYY-MM-DD', 'allowEmpty'=>false),
// Check for UNIQUE
// USAGE: array('email', 'unique'),
public function unique( $attribute, $params )
{
if( self::model()->count( 't.email=:email', array( ':email' => $this->attribute ) ) > 0 ) $this->addError('email', 'Email already exists');
Example 5: Generating dropdownlist with option groups.
from http://www.yiiframework.com/wiki/48/by-example-chtml/#hh4
If you need to generate dropdownlist using both optgroup and option tags use the following code.
<div class="cars-select">
<?php echo CHtml::dropDownList('Cars', 'car_id', array(
'Mazda'=>array(
'mazda-rx7'=>'RX7',
'mazda-rx5'=>'RX5',
@Narven
Narven / yii_rules
Last active January 3, 2016 07:29
Yii Active Record Rules
<?php
public function rules()
{
return array(
array( 'field', 'required' ),
array( 'field', 'numerical', 'integerOnly' => true ),
array( 'field, field2', 'length', 'max' => 10 ),
array( 'field, field2', 'safe', 'on' => 'search' ),
array( 'status', 'safe' ),
@Narven
Narven / yii criteria
Last active January 3, 2016 12:39
yii CDbCriteria examples
<?php
$criteria=new CDbCriteria;
$criteria->addSearchCondition('title', $_GET['Press']['title']);
$criteria->addSearchCondition('body', $_GET['Press']['title']);
$presses=Press::model()->findAll($criteria);
// SELECT * FROM 'presses' 't' WHERE (title LIKE :ycp0) AND (body LIKE :ycp1)
$criteria=new CDbCriteria;
<?php
/**
* Controller is the customized base controller class.
* All controller classes for this application should extend from this base class.
*/
class RestController extends CController
{
/**
* @var string the default layout for the controller view. Defaults to '//layouts/column1',
* meaning using a single column layout. See 'protected/views/layouts/column1.php'.
#define DEBUG_CONSOLE
#define DEBUG_LEVEL_LOG
#define DEBUG_LEVEL_WARN
#define DEBUG_LEVEL_ERROR
#if (UNITY_EDITOR || DEVELOPMENT_BUILD)
#define DEBUG
#endif
#if (UNITY_IOS || UNITY_ANDROID)
@Narven
Narven / unity3d_scrolling_texture
Created May 7, 2014 07:34
Unity3d javascript scrolling texture
var scrollSpeed = 0.90;
var scrollSpeed2 = 0.90;
function FixedUpdate()
{
var offset = Time.time * scrollSpeed;