php - Passing result from Model to Controller dependant on result in Codeigniter -


The best way to do this can not be to get my head - I have a model that adds a product for shopping The car is; $ this-> Db- & gt; Choose ('*'); $ This- & gt; Db- & gt; ('Product'); $ This- & gt; Db- & gt; Where ('product_id', $ PID); $ Query = $ this- & gt; Db- & gt; get receive (); $ Products = $ query- & gt; Result_are (); $ Stock = $ product ['0'] ['stock']; $ Quantity = 2; $ Cart = $ this- & gt; Cart- & gt; material (); $ Found = wrong; Foreign currency ($ cart $ item) {if ($ pid == $ item ['id']) {If ($ item ['quantity'] + $ quantity & lt; = $ stock) {$ this- & Gt; Cart- & Gt; Update (Array ('queued' => gtc: $ item ['queued'], 'qty' = & gt; $ item ['quantity'] + $ quantity); $ found = true; $ message to send message Added}} and {$ found = true; $ send message is not telling enough stock}}} if ($$ == incorrect) {$ data = array ('id' => products [0] [ $ '[products],' product_id ' ); If ($ quantity & lt; = $ stock) {$ this-> Cart-> Enter ($ data);} and {echo "Not enough stock";}} $ this- & gt; Cart-> Content ();

What is the best way to return messages to the controller so that I can show the user that the item has been added / not enough stock?

I have read that I can use "return" - but as I am returning the $ - this-> Cart-> Content (); I'm not sure where I want to go.

I may be completely wrong on this I can see from, but if someone can tell me the best way to handle this situation.

Try to do something like this: $ data = array (); $ Data ['cart'] = $ this- & gt; Cart- & gt; material (); $ Data ['msg'] = 'Your message is here'; $ Return data;

And, in your controller, just take out the necessary elements, such as: $ return = $ this-> Model- & gt; Ceremony (); // Your model is returned here $ [$$$$$] ['carriage'] returns; // cart content $ msg = $ return ['msg']; // module

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -