Symfony PHP Missing Argument Error when using Join - php

Hi I am using a PHP Symfony project and am trying to use the generated model peer class to make a query.
The model has generated the method "doSelectJoinMeetingItems" which is supposed to join my Meeting Actions Table to my Meeting Items table (see a quote of the generated code below).
However, when using this method I get the following error: Warning: Missing argument 1 for sfComponent::__construct(), - see in full below.
Does anyone know why this is happening? All I am doing is using Symfonys own generated methods to try and get data through my ORM to me!
Thanks for your time,
My code:
Inside MeetingMeetingsPeer
return self::doSelectJoinMeetingItems(new Criteria());
The auto generated baseMeetingActionsPeer
public static function doSelectJoinMeetingItems(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
{
$criteria = clone $criteria;
// Set the correct dbName if it has not been overridden
if ($criteria->getDbName() == Propel::getDefaultDB()) {
$criteria->setDbName(self::DATABASE_NAME);
}
MeetingActionsPeer::addSelectColumns($criteria);
$startcol = (MeetingActionsPeer::NUM_COLUMNS - MeetingActionsPeer::NUM_LAZY_LOAD_COLUMNS);
MeetingItemsPeer::addSelectColumns($criteria);
$criteria->addJoin(MeetingActionsPeer::ITEM_ID, MeetingItemsPeer::ID, $join_behavior);
// symfony_behaviors behavior
foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook)
{
call_user_func($sf_hook, 'BaseMeetingActionsPeer', $criteria, $con);
}
$stmt = BasePeer::doSelect($criteria, $con);
$results = array();
while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
$key1 = MeetingActionsPeer::getPrimaryKeyHashFromRow($row, 0);
if (null !== ($obj1 = MeetingActionsPeer::getInstanceFromPool($key1))) {
// We no longer rehydrate the object, since this can cause data loss.
// See http://propel.phpdb.org/trac/ticket/509
// $obj1->hydrate($row, 0, true); // rehydrate
} else {
$cls = MeetingActionsPeer::getOMClass(false);
$obj1 = new $cls();
$obj1->hydrate($row);
MeetingActionsPeer::addInstanceToPool($obj1, $key1);
} // if $obj1 already loaded
$key2 = MeetingItemsPeer::getPrimaryKeyHashFromRow($row, $startcol);
if ($key2 !== null) {
$obj2 = MeetingItemsPeer::getInstanceFromPool($key2);
if (!$obj2) {
$cls = MeetingItemsPeer::getOMClass(false);
$obj2 = new $cls();
$obj2->hydrate($row, $startcol);
MeetingItemsPeer::addInstanceToPool($obj2, $key2);
} // if obj2 already loaded
// Add the $obj1 (MeetingActions) to $obj2 (MeetingItems)
$obj2->addMeetingActions($obj1);
} // if joined row was not null
$results[] = $obj1;
}
$stmt->closeCursor();
return $results;
}
The Error in Full
Warning: Missing argument 1 for sfComponent::__construct(), called in /var/www/html/dev/meeting/lib/model/om/BaseMeetingActionsPeer.php on line 584 and defined in /var/www/html/dev/meeting/lib/vendor/symfony/lib/action/sfComponent.class.php on line 36
Warning: Missing argument 2 for sfComponent::__construct(), called in /var/www/html/dev/meeting/lib/model/om/BaseMeetingActionsPeer.php on line 584 and defined in /var/www/html/dev/meeting/lib/vendor/symfony/lib/action/sfComponent.class.php on line 36
Warning: Missing argument 3 for sfComponent::__construct(), called in /var/www/html/dev/meeting/lib/model/om/BaseMeetingActionsPeer.php on line 584 and defined in /var/www/html/dev/meeting/lib/vendor/symfony/lib/action/sfComponent.class.php on line 36
Notice: Undefined variable: context in /var/www/html/dev/meeting/lib/vendor/symfony/lib/action/sfComponent.class.php on line 38
Fatal error: Call to a member function getEventDispatcher() on a non-object in /var/www/html/dev/meeting/lib/vendor/symfony/lib/action/sfComponent.class.php on line 55
The lines 582 to 586 are as follows:
582 $cls = MeetingActionsPeer::getOMClass(false);
583
584 $obj1 = new $cls();
585 $obj1->hydrate($row);
586 MeetingActionsPeer::addInstanceToPool($obj1, $key1);
Line 36 from sfComponnent.class.php
36 public function __construct($context, $moduleName, $actionName)
37 {
38 $this->initialize($context, $moduleName, $actionName);
39 }

I have located the problem, in Symfony 1.4 you cannot have a class that ends in actions for example UserActions or GroupActions (wish this was properly documented somewhere).
I wish this was better documented and the error was more useful!
a classname (in the schema.yml) which ends with '%Actions' for example
UserActions? (symfony 1.4.10). An error was thrown when i added an
extra field (with validation) in the form of the object related to
this '*Actions'.
wrapped: Warning: Missing argument 2 for sfComponent::__construct(), called in
/Users/Shared/Library/symfony-1.4.10/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Table.php
on line 301 and defined in /Users/Shared/Library/symfony-1.4.10/lib/action/sfComponent.class.php on line 36
Warning: Missing argument 3 for sfComponent::__construct(), called in
/Users/Shared/Library/symfony-1.4.10/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Table.php
on line 301 and defined in /Users/Shared/Library/symfony-1.4.10/lib/action/sfComponent.class.php on line 36]
See post at http://trac.symfony-project.org/wiki/ReservedWords

Related

Non-static method should not be called statically in Kohana 2.3.4

i've moved my Kohana 2.3.4 installation to a new hosting with php7 (probably that's a root of the issue) and now i am getting the following error:
Uncaught PHP Error: Non-static method AdminHook::menu_tree() should not be called statically in file system/core/Event.php on line 209
Here's my Event.php around line 209 (call_user_func($callback); is at line 209):
public static function run($name, & $data = NULL)
{
if ( ! empty(self::$events[$name]))
{
// So callbacks can access Event::$data
self::$data =& $data;
$callbacks = self::get($name);
foreach ($callbacks as $callback)
{
call_user_func($callback); // LINE 209
}
// Do this to prevent data from getting 'stuck'
$clear_data = '';
self::$data =& $clear_data;
}
// The event has been run!
self::$has_run[$name] = $name;
}
And here's the AdminHook class:
class AdminHook {
public function menu_tree(){
$session = Session::instance();
if(isset($_GET['_ml']) AND $_GET['_ml'] == 1) {
$session->set('menuLink', 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
//url::redirect(url::current());
}
global $menuLink;
$menuLink = $session->get('menuLink');
}
}
If i set menu_tree function to static, i get the following error:
Uncaught PHP Error: Declaration of Menu_Model::validate(array &$array, $save = false) should be compatible with ORM_Core::validate(Validation $array, $save = false) in file application/models/menu.php on line 18
I've been trying to find a solution for the next couple of days, but can't seem to find one. Any help is highly appreciated!
Errors are not related to each other. By simply setting that method as static, php goes to showing the next error.
You have bad Menu_Model declaration. It mut be compatible with ORM_Core::validate
Menu_Model::validate(/*bad: array & */ Validation $array, $save = false)

codeigniter 2 with doctrine 2 - I can insert data in to tables but I can't get data back

I am still trying to study doctrine so I am following online tutorial by that I could insert data in to a mysql table. like this.
public function createObjects() {
// create a new user object
$user = new Entities\User;
$user->setFirstName('Joel');
$user->setLastName('Verhagen');
$user->setPassword(md5('Emma Watson'));
$this->doctrine->em->persist($user);
$this->doctrine->em->flush();
}
Then I tried to get the data back like this.
public function testing() {
// $user = new Entities\User;
$article = new Entities\Article;
$firstname = $this->doctrine->em->getRepository($article);
$products = $firstname->findAll();
foreach ($products as $product) {
echo sprintf("-%s\n", $product->getContent());
}
}
But I am getting following errors can some one help me on this?
Severity: Warning
Message: ltrim() expects parameter 1 to be string, object given
Filename: ORM/EntityManager.php
Severity: Warning
Message: class_parents(): object or string expected
Filename: Mapping/RuntimeReflectionService.php
Severity: Warning
Message: array_reverse() expects parameter 1 to be array, boolean given
Filename: Mapping/AbstractClassMetadataFactory.php
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: Mapping/AbstractClassMetadataFactory.php
Fatal error: Uncaught exception 'ReflectionException' with message 'Class does not exist' in E:\xampp\htdocs\shoping\application\libraries\Doctrine\Common\Persistence\Mapping\RuntimeReflectionService.php:73 Stack trace: #0 E:\xampp\htdocs\shoping\application\libraries\Doctrine\Common\Persistence\Mapping\RuntimeReflectionService.php(73): ReflectionClass->__construct('') #1 E:\xampp\htdocs\shoping\application\libraries\Doctrine\ORM\Mapping\ClassMetadataInfo.php(867): Doctrine\Common\Persistence\Mapping\RuntimeReflectionService->getClass(NULL) #2 E:\xampp\htdocs\shoping\application\libraries\Doctrine\ORM\Mapping\ClassMetadataFactory.php(517): Doctrine\ORM\Mapping\ClassMetadataInfo->initializeReflection(Object(Doctrine\Common\Persistence\Mapping\RuntimeReflectionService)) #3 E:\xampp\htdocs\shoping\application\libraries\Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory.php(300): Doctrine\ORM\Mapping\ClassMetadataFactory->initializeReflection(Object(Doctrine\ORM\Mapping\ClassMetadata), Object(Doctrine\Common\Pe in E:\xampp\htdocs\shoping\application\libraries\Doctrine\Common\Persistence\Mapping\RuntimeReflectionService.php on line 73
Tried and tried and at last I found a way to go.
public function testing() {
// $user = new Entities\User;
$article = new Entities\Article;
$firstname = $this->doctrine->em->getRepository('Entities\Article');
$products = $firstname->findAll();
foreach ($products as $product) {
echo sprintf("-%s\n", $product->getContent());
}
// $products = $article->getContent();
// echo $products.'fdsf';
}

Undefined variable in __construct()... but I did define it

I've written the following piece of code:
Class stackOverflowExample {
private $hash;
private $cookie_file;
public function __construct(){
#session_start();
if(isset($_SESSION['gc_hash'])){
$this->$hash = $_SESSION['gc_hash'];
}else{
$this->$hash = md5(time());
$_SESSION['gc_hash'] = $this->$hash;
}
$this->$cookie_file = "./cookies/{$this->$hash}.txt";
}
}
But I'm getting this error
Notice: Undefined variable: hash in
/var/www/gausie/gc/GeoCaching.Class.php on line 21
Fatal error: Cannot access empty property in
/var/www/gausie/gc/GeoCaching.Class.php on line 21
In the original code, line 21 refers to $this->$hash = $_SESSION['gc_hash'];.
I can't see why this is happening, although I'm new to OO PHP. Any ideas?
just replace $this->$hash by $this->hash
$this->$hash means variable with name equals to variable $hash value

How to handle erroneous argument type in this situation?

I'd like to use stdClass to store options for some methods, instead of passing huge lists of variables (inspired by javascript-style coding)
However, I'd like to make sure I'm always getting an instance of stdClass as an argument. I know I can add a hint in the argument (gb::search below) but when I deliberately try to break it, I'm not sure how to handle the error.
Any tips?
class gb extends CI_Model {
protected $searchtypes = array('full','partial');
protected $endpoint = "https://local.endpoint";
function __construct() {
parent::__construct();
// sample search
$options = new stdClass();
$options->term = 'sample search';
$options->type = 'full';
$this->search($options);
}
function clean_term($term){
$term = trim($term);
return $term;
}
function search(stdClass $options){
$term = $options->term;
$type = $options->type;
// make sure we're doing a valid search
if (!$term || !in_array($type, $this->searchtypes)) {
return false;
}
$term = $this->clean_term($term); // etc
}
The error it throws is something like:
A PHP Error was encountered
Severity: 4096
Message: Argument 1 passed to gb::search() must be an instance of stdClass, null given, called in /application/models/gb.php on line 20 and defined
Filename: models/gb.php
Line Number: 29
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/gb.php
Line Number: 31
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/gb.php
Line Number: 32
Any ideas how to approach this from a CodeIgniter point of view?
if I remember - mistyped argument should raise E_RECOVERABLE_ERROR, so, it triggers error handler but execution continues. So, you have two options basically.
One is to throw exception in error handler when E_RECOVERABLE_ERROR is encountered. To halt execution.
Another - check type with instanceof stdClass and do what you suppose - raise exception or return something.
UPDATE In your case your framework (CI is for CodeIgniter?) sets error handler (somewhere using set_error_handler). So, after logging or printing error message execution continues. (If there was not handler you would get fatal error). Just test type of argument manually:
function search(stdClass $options){
// test type for sure, because of recoverable error
if (!($options instanceof stdClass)) {
return false; // or throw new InvalidArgumentException('Parameter should be instance of stdClass');
}
$term = $options->term;
$type = $options->type;
// make sure we're doing a valid search
if (!$term || !in_array($type, $this->searchtypes)) {
return false;
}
$term = $this->clean_term($term); // etc
}

Error defining variable in PHP object

I am getting the following error in the following code:
Class primeField implements field {
private $intmodulus = '';
public function generator(){
return ;
}
public function modulus(){
return $this->$intmodulus;
}
public function __construct($modulus , $base=0) {
if (is_resource($modulus) && get_resource_type($modulus) == "GMP integer"){
$this->$intmodulus = $modulus;
} else{
$this->$intmodulus = gmp_init($modulus , $base); \\line 70
}
}
}
$a = new primeField(11);
$a->modulus();
Notice: Undefined variable: intmodulus in /Users/admin/PHP ECC/finitefield.php on line 70
Fatal error: Cannot access empty property in /Users/admin/PHP ECC/finitefield.php on line 70
Why
The syntax is
$this->intmodulus
not $this->$intmodulus.
You get an error saying "cannot access empty property" because $intmodulus is undefined and hence accessing it gives NULL. The NULL gets converted into an empty string when you attempt to use it as a property name.
If the value of $intmodulus was the name of a valid property (e.g. if $intmodulus == "intmodulus"), you would be accessing the property with that name.
$this->$intmodulus should be $this->intmodulus
See the PHP documentation for Variable variables for info on what is happening.

Categories