AclExtras Warning Error - cakephp

In CakePHP 2 book / Acl Tutorial / Part 2, I am executing the command:
./Console/cake AclExtras.AclExtras aco_sync
and I get a warning error:
Warning Error: Argument 1 passed to Component::startup() must be an instance of Controller,
null given, called in
/opt/lampp/htdocs/acl/app/Plugin/AclExtras/Console/Command/AclExtrasShell.php
on line 80 and defined in [/opt/lampp/htdocs/acl/lib/Cake/Controller/Component.php, line 119]
The acos table gets populated with NULL in model field and NULL in all fields of the foreign_key.
How can I fix this error?
ThAnKs

in AclExtras/Console/Command, please change startup function to :
public function startup() {
parent::startup();
$controller = new Controller();
$collection = new ComponentCollection();
$this->Acl = new AclComponent($collection);
$this->Acl->startup($controller);
$this->Aco = $this->Acl->Aco;
}

Related

Facing Problem Insert Session id In my Database

I create session id randomly in my controller,but i can't store my session id in my database .I got an error Like this Trying to access array offset on value of type null. Thanks
public function addtocart(Request $request){
$cart=New Cart();
$session_id = Session::get('session_id');
if (!isset($session_id)) {
$session_id = str_random(40);
Session::put('session_id', $session_id);
}
$cart->product_id=$request['product_id'];
$cart->product_name=$request['product_name'];
$cart->product_code=$request['product_code'];
$cart->product_color=$request['product_color'];
$cart->price=$request['price'];
$cart->size=$request['size'];
$cart->quantity=$request['quantity'];
$cart-> $request['session_id'];
$cart->save();
return $cart;
}
On line 3 you store the session id in the $session_id variable.
You then call $cart-> $request['session_id'] which tries to access the $request['session_id'] property. I'm not sure if this is valid PHP but I am sure that this property does not exist.
I assume that wat you want to do is:
$cart->session_id = $session_id

Symfony2.8 with sonataEcommerce2.1.1 single Product page "requires that you provide a value for the "$product" argument"

I am using sonata-ecommerce. When I try to open single product page then Controller error occure.
Here is detailed error.
"Application\Sonata\ProductBundle\Controller\ProductController::viewAction()" requires that you provide a value for the "$product" argument (because there is no default value or because there is a non optional argument after this one).
No need to change the extend.
Here is my Code:-
Copy viewAction from vendor/sonata-project/ecommerce/ProductBundle/controller/Basecontroller and place it in src/Application/Sonata/Controller/ProductController.
After copy assign $product = null in the ApplicationSonataProductBundle.
public function viewAction($product = null) {
//Add these lines.
$slug = $this->getRequest()->get('slug');
$productId = $this->getRequest()->get('productId');
$product = $this->get('sonata.product.set.manager')->findEnabledFromIdAndSlug($productId, $slug);
....
}

Using function max cakephp in query

Hello everyone como estan will see I have this query in SQL
SELECT MAX(id_alternativa) FROM pregunta_alternativa WHERE id_pregunta = 7
which I'm doing in cakephp using the MAX function framework
public function register() {
$query = $this->PreguntasAlternativas->find()
->select([
'id_alternativa' => $query->func()->max(['id_alternativa'])
])->where(['id_pregunta' => '7']);
$this->set('alternatives',$query); }
but it shows this is the message Error
Error: Call to a member function func() on null File C:\xampp\htdocs\serapp\src\Controller\PreguntasAlternativasController.php Line: 14
as I see documentation so their functions are used
Sql Functions Cakephp
thanks for helping me
the solution was simple place it here, referring to the documentation
public function register() {
$query = $this->PreguntasAlternativas->find();
$query->select(['id_alternativa' => $query->func()->max('id_alternativa')
])->where(['id_pregunta' => '7']);
You must be setear variable $query

How to add to an array of objects, an object that is inherited? (Swift, XCode)

var allCards = [CCard]
var cardsMade = 0
^^ is outside of my view controller class as to make it global and accessible in all other view controller files.
in another view controller i have
#IBAction func saveInfo(sender: UIButton) {
let a = CCreature(n: cName!, e: cExpansion, ec: cEnergy!, tc: cTurnCount!,
ef: cEffect!, at: cStrength!, ht:cHealth!, sp: cSpeed!, sb: false)
allCards.append(a)
cardsMade++}
so when the saveInfo button is pressed, i put all the information the user has typed (which were in UITextFields, and then saved into the corresponding vairables cEnergy etc..) into a subclass of CCard called CCreature, with all of the information. After I create the instance of the class, i am trying to store in the array allCards. I am getting an error on the line:
var allCards = [CCard]
Expected member name or constructor call after type name
And in the line where a is appended to the array i am getting this error:
Cannot convert value of type 'CCreature' to expected argument type 'inout Array < CCard >'
I was also getting this error message before, when my program was compiling:
fatal error: Array index out of range
Any ideas?
As you have it [CCard] is a type declaration, you could use it as:
var allCards : [CCard]
but, that won't actually initialize allCards to be useful, alternatively, you could actually create the array and initialize it using:
var allCards = [CCard]()
Where you're using the default array constructor
It's not the entirety of your example, because you didn't include a lot of the pieces, but stripped down to show usage, would be:
var allCards = [CCard]()
func saveInfo() {
let a = CCreature()
allCards.append(a)
}

Use twitchAPI with cake

since a few hours i'm trying to implement the twitchAPI in my cake projet. a long time ago i made this little script in basic php.
$channelName = "gamespot";
$json_file = #file_get_contents("http://api.justin.tv/api/stream/list.json?channel={$channelName}", 0, null, null);
$json_array = json_decode($json_file, true);
#$json_array[0] && $json_array[0]['name'] == "live_user_{$channelName}";
#$title = $json_array[0]['channel']['status'];
#$game = $json_array[0]['meta_game'];
#$chanel_view = $json_array[0]['channel_count'];
#$totalchanelview = $json_array[0]['channel_view_count'];
but i don't know how to add this lines on my controller
For know i've just find this
public function twitch() {
$json = file_get_contents('http://api.justin.tv/api/stream/list.json?channel=manvsgame');
$twitch = json_decode($json);
$totalchanelview = $twitch[0]['channel_view_count'];
$this->set('twitch', 'totalchanelview');
}
but of course i've this error
Fatal error: Cannot use object of type stdClass as array in /Users/*/Desktop/Websites/**/app/Controller/UsersController.php on line 29
anyone can explain to me how i can use this API?
thanks in advance and have a nice day/night :)
okey first thanks to help me. i still have a little "logic problem"
my function is something like that:
public function twitch() {
$json = file_get_contents('http://api.justin.tv/api/stream/list.json?channel=gamespot');
$twitch = json_decode($json, true);
$this->set('json', $twitch);
}
but know, what can I write to my view to see my informations (like the title of my stream for exemple.
I test with
echo $twitch[0]['title']; (it's my line 1)
bit i've this error
Notice (8): Undefined variable: twitch [APP/View/Users/admin_dashboard.ctp, line 1]
$twitch = json_decode($json, true); // add true param
$twitch[0]['channel_view_count'];
adding true returns the data as an associated array instead

Resources