Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: flypages with different sql request

flypages with different sql request 01 Nov 2013 14:05 #11511

  • ewajoom
  • ewajoom's Avatar
  • Offline
  • Junior Member
  • Posts: 36
  • Thank you received: 2
  • Karma: 0
Hi,

It seems that all flypages are using the same sql request.
Is it possible to have different sql for each flypage ?

Thanks
The administrator has disabled public write access.

flypages with different sql request 01 Nov 2013 18:20 #11512

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Yes you can.
prepareQuery()... + state vars

Forms, Flys, Lists, are always creating the SQL creation for different contexts. (Different layouts)
The stateVar name is 'context'.

The access controls and filters are always instanced per security.
Also, there is no other place to code your SQL. All you SQL requests must be called by prepareQuery()

The default context is '[view].[layout]' but you can use what you want, even not name spaced (without points ' . ' )
The context var is also used to store permanent vars, such as filters. So this context var is very important if you do not have stange surprises when filters are not isolated from their calling contexts.

Hope it helps
Coding is now a piece of cake
The administrator has disabled public write access.

flypages with different sql request 01 Nov 2013 19:43 #11515

  • ewajoom
  • ewajoom's Avatar
  • Offline
  • Junior Member
  • Posts: 36
  • Thank you received: 2
  • Karma: 0
Thanks for all those informations!
Yes it helps : I've added my query in prepareQuery, in a case "fly_1".

But now I don't understand where to change/load the context.
I've tried in tmpl : $this->setState('context', 'fly_1');
It generates an error "Call to undefined method EkistatsViewEvalitem::setState()"
The administrator has disabled public write access.

flypages with different sql request 01 Nov 2013 20:06 #11516

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
state vars applies on models not on views.


Then, when the items are created, the SQL is requesed, so the state vars need to be setted up before that moment.

In your view,

After $model initialization
and
Before $model-> getItem()
Coding is now a piece of cake
The administrator has disabled public write access.
The following user(s) said Thank You: ewajoom

flypages with different sql request 01 Nov 2013 21:39 #11520

  • ewajoom
  • ewajoom's Avatar
  • Offline
  • Junior Member
  • Posts: 36
  • Thank you received: 2
  • Karma: 0
fine it works. Datas from my specific sql appears without error now in flypage.
Thanks!
The administrator has disabled public write access.

flypages with different sql request 02 Nov 2013 18:53 #11524

  • ewajoom
  • ewajoom's Avatar
  • Offline
  • Junior Member
  • Posts: 36
  • Thank you received: 2
  • Karma: 0
Something wrong : I can only have [view].[layout] or flypage data in the view.

view.html.php, just before $this->get('Item'), I've added the two contexts as you show me :
$state->set('context', 'evalitem.synthese');
$state->set('context', 'evalitem.fly1');
in model I've added a case 'evalitem.fly1' with specific SQL request.

$state->set('context', 'evalitem.synthese');
$state->set('context', 'evalitem.fly1');
-> No data on flypage

// $state->set('context', 'evalitem.synthese');
$state->set('context', 'evalitem.fly1');
-> Datas are okay for fly1 but no datas on the rest of the page

$state->set('context', 'evalitem.synthese');
//$state->set('context', 'evalitem.fly1');
-> Datas are okay for the rest of the page, but no data on flypage

any suggestion ?

Thanks
The administrator has disabled public write access.

flypages with different sql request 03 Nov 2013 18:18 #11527

  • ewajoom
  • ewajoom's Avatar
  • Offline
  • Junior Member
  • Posts: 36
  • Thank you received: 2
  • Karma: 0
okay, I understand why : there are "break" after each sql in cases....
In fact I understand that all this creates a single model instance...
Thanks
The administrator has disabled public write access.

flypages with different sql request 02 Apr 2014 11:51 #12383

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 279
  • Thank you received: 36
  • Karma: 22
Hi all,

Very interested with this post because this is what I try to do :
Original Project : JBreedingV3.x
Framework: 3.0
Frontend Source : components/com_jbreeding/views/portee/view.html.php

Jcook code :
// Initialiase variables.
	$this->model	= $model	= $this->getModel();
	$this->state	= $state	= $this->get('State');
	$state->set('context', 'portee.porteattendue');
	$this->item		= $item		= $this->get('Item');

Then I want to catch datas (previous puppies) from another Table (pedigrees)
this sql 'where clause' will be built with 2 keys results ($item->fname and $item->mname )

I tried something like this ... and add a case 'portee.previouspuppies' in model/portee.php ...
		$state->set('context', 'portee.previouspuppies');
		$this->previous		= $previous		= $this->get('Items');

but this don't work.
What will be the best way get this datas and display in this view ?
Thanks for help
The administrator has disabled public write access.

flypages with different sql request 04 Apr 2014 06:34 #12391

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 279
  • Thank you received: 36
  • Karma: 22
Hi admin,

still trying to find a solution, I read and read j-cook docs...

In the item view, I tried this :
	$modelPed = CkJModel::getInstance('pedigrees', 'JbreedingModel');   // ==> OK
	$modelPed->setState('pedigrees.previouspuppies');  // ==> OK
	$this->items	= $items 	= $modelPed->getItems(); // ==> NOK ( invalid query )

But process failed into 'invalid query' before executing my model query in the PrepareQuery case .'pedigrees.previouspuppies':
The administrator has disabled public write access.

flypages with different sql request 04 Apr 2014 06:52 #12392

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Dump the generated SQL query, and try it directly inside phpmyadmin to see where is the error.

In your previous post, you was mixing ITEM and LIST models. Now, everything seems correct.

To debug this kind of issue (wich happens me often when I develop), try to reduce the query with commenting the lines.

Also be careful to the JOINS, because when you have double instances, cook will make them unique ONLY if they are perfectly EXACT syntax.
I try to explain better :
depending on: context, filters, ... the query contains more or less JOINS. some combinasons invoke sometimes twice the same joining, but then cook reduce them to unique statement. It can do the job only if those statement are perfectly the same. Check the spaces, the quotes, etc...
Maybe it is not your problem, but it could.
Coding is now a piece of cake
The administrator has disabled public write access.

flypages with different sql request 04 Apr 2014 07:09 #12394

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 279
  • Thank you received: 36
  • Karma: 22
Hi,
thanks for help,

OK, it's why I set a simple query, but its failed before executing this, and I can not see witch query it is in the debug. invalid query, that's all .


views/portee/view.html.php
// Initialiase variables.
		$this->model	= $model	= $this->getModel();
		$this->state	= $state	= $this->get('State');
		$state->set('context', 'portee.porteattendue');
		$this->item		= $item		= $this->get('Item');
		
		// adding custom code 
		$modelPed = CkJModel::getInstance('pedigrees', 'JbreedingModel');
		$modelPed->setState('pedigrees.previouspuppies'); 
		$this->items	= $items 	= $modelPed->getItems();

models/pedigrees/pedigrees.php
			case 'pedigrees.previouspuppies':
				//SELECT : raw complete query without joins
				$this->addSelect('a.*');

				// Disable the pagination
				$this->setState('list.limit', null);
				$this->setState('list.start', null);
				break;
Last Edit: 04 Apr 2014 07:10 by liubov.
The administrator has disabled public write access.

flypages with different sql request 04 Apr 2014 07:24 #12395

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
At the end of prepareQuery(), dump :
string($query)

What happen if you do not use this context ?

Arf, i see : this is the correct code :

$modelPed->setState('context','pedigrees.previouspuppies');

The state var name is 'context'
Coding is now a piece of cake
The administrator has disabled public write access.

flypages with different sql request 04 Apr 2014 08:47 #12396

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 279
  • Thank you received: 36
  • Karma: 22
Yes, I add 'context' var, and try with and without setstate, but not better !
	// adding custom code 
	$modelPed = CkJModel::getInstance('pedigrees', 'JbreedingModel');
	$modelPed->setState('context, 'pedigrees.previouspuppies'); 
	$this->items	= $items 	= $modelPed->getItems();

the Dump result is not displayed because I think the query error is before the
         protected function prepareQuery(&$query)

But where ???
do the $modelPed->getItems(); directly jump in the Models ???
Last Edit: 04 Apr 2014 08:47 by liubov.
The administrator has disabled public write access.

flypages with different sql request 04 Apr 2014 09:14 #12397

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Try to follow the trace from the list model class.

The call stack is calling native Joomla classes, and cook overrides in classes/models/ folder.

Try to interrupt to process and see where is your problem.
I guess this is your production component and so I cannot see it from the builder.

It looks really strange. I never had this problem.

Consider that your model is also calling SQL for pagination and counting the items. This is another SQL maybe you have forgotten.
I really have no idea if you do not furnish more details.

What happen if you remove the context state var call ?
Try to reduce everything to the minimum to find your problem.
Try to load this SQL directly from its own view (pedigrees view file)
Try to work on this case alone with fresh generated component.

If you still have problem, then I am ok to work for you and check your component. Send me this in private, I will tell you the price for debug.
Coding is now a piece of cake
The administrator has disabled public write access.

flypages with different sql request 04 Apr 2014 11:15 #12398

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 279
  • Thank you received: 36
  • Karma: 22
This not my production component which is under J2.5 yet. I work on my Joomla3.2 development plateform.

liubov.net/joomla32

Backend is now full completed (no problem with all I wanted to do), and I am now working on Frontend layouts.

I have well experiment the new classes, method, ... of the J-cook V2.6. Great !

So will try all your advices ...

Thanks
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Time to create page: 0.104 seconds

Get Started