Created
September 17, 2013 08:27
-
-
Save xboston/6591567 to your computer and use it in GitHub Desktop.
Phalcon model public/protected var's test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Phalcon\DI , Phalcon\Db\Adapter\Pdo\Mysql as Connection , Phalcon\Mvc\Model\Manager as ModelsManager , Phalcon\Mvc\Model\Metadata\Memory as MetaData , Phalcon\Mvc\Model; | |
$di = new DI(); | |
//Setup a connection | |
$di->set( | |
'db' , | |
new Connection(array( | |
'adapter' => 'Mysql' , | |
'host' => 'localhost' , | |
'username' => 'root' , | |
'password' => '' , | |
'dbname' => 'test' , | |
'charset' => 'utf8' | |
)) | |
); | |
//Set a models manager | |
$di->set('modelsManager' , new ModelsManager()); | |
//Use the memory meta-data adapter or other | |
$di->set('modelsMetadata' , new MetaData()); | |
class modeltest extends \Phalcon\Mvc\Model | |
{ | |
public $publicvar; | |
protected $protectedvar; | |
public function setProtectedvar($value) | |
{ | |
$this->protectedvar = $value; | |
} | |
public function getProtectedvar() | |
{ | |
return $this->protectedvar; | |
} | |
} | |
$modelTest = new modeltest(); | |
$modelTest->setProtectedvar('testProtect'); | |
$modelTest->publicvar = 'testPublic'; | |
echo $modelTest->getProtectedvar(); | |
echo '<br />'; | |
echo $modelTest->publicvar; | |
echo '<br />'; | |
$result = $modelTest->toArray(); | |
print_r($result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment