Re: [fw-general] Zend\Sql\TableGateway|Where|Predicate bug?

2013-09-15 Thread David Muir

On 15/09/13 22:20, András Csányi wrote:

Hi All,

I put together my application and I use TableGateway pattern based on
the tutorial. I got some help how to select data from the database if
there are multiple where conditions. It is quite good and easy when
you got the way how it works.

Unfortunately, I found something interesting:

I have this code in one of my tablegateway class:

public function selectWith($select = null) {

 $filter = new Predicate();
 $filter->like('category_name',"%dess%")
 ->OR
 ->like('category_desc', "%ks%");

 var_dump($this->tableGateway->select(function(Select $select)
use ($filter) {
 $select->where($filter);
 }));

 return $this->tableGateway->select(function(Select $select)
use ($filter) {
 $select->where($filter);
 });
 }

According to the dump the executed select is the following:

'SELECT `categories`.* FROM `categories` WHERE (`category_name` LIKE
:where1 OR `category_desc` LIKE :where2)'

But it should be this:

SELECT `categories`.* FROM `categories` WHERE (`category_name` LIKE
'%dess%' OR `category_desc` LIKE '%ks%')

The result is the same if I use Where instead of Predicate.

I use ZF 2.2.2.

Is this a known issue or I did something wrong?

Thanks for any help in advance!

András




Looks correct to me.
The statement will be prepared with the :where1 and :where2 
placeholders, then executed with the values "%dess%" and "%ks%".


Cheers,
David


--
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




[fw-general] Re: Display other module content within module in zend framework 2

2013-09-15 Thread Marco Pivetta
I think so, but if the other controller calls the `layout` helper, then
you'll still see the different layout.

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/


On 15 September 2013 20:28, facCoder [via Zend Framework Community] <
ml-node+s634137n4660979...@n4.nabble.com> wrote:

> Thanks for your reply...
>
> Basically, when I call the controller's action(method) of another module,
> it rendered its layout. I want this layout to be render on current layout
> as partial layout. i.e. on particular div i want to render this layout.
>
> Is it possible???
>
>
> On Sun, Sep 15, 2013 at 6:35 AM, Marco Pivetta [via Zend Framework
> Community] <[hidden 
> email]
> > wrote:
>
>> Layouts are just named scripts (the names are used by the view resolver
>> to find out what the path to the script is).
>>
>> There's two ways to achieve what you want to do:
>>
>>   1 - use the `layout` controller helper
>>  2 - modify the view model contained in your application's MvcEvent
>> (->getViewModel()) so that the template name corresponds to the layout you
>> want.
>>
>>
>> Marco Pivetta
>>
>> http://twitter.com/Ocramius
>>
>> http://ocramius.github.com/
>>
>>
>> On 14 September 2013 20:58, facCoder [via Zend Framework Community] <[hidden
>> email] > wrote:
>>
>>> I am new to zend framework 2. I want to display other module
>>> contents(layout) within module.
>>>
>>> Means i am in abc module and x layout is rendered. On click to anchor
>>> tag i want to show other module layout in abc moudule x layout.
>>>
>>> Similar to partial layouts.
>>>
>>>
>>> --
>>>  If you reply to this email, your message will be added to the
>>> discussion below:
>>>
>>> http://zend-framework-community.634137.n4.nabble.com/Display-other-module-content-within-module-in-zend-framework-2-tp4660968.html
>>>  To start a new topic under Zend Framework, email [hidden 
>>> email]
>>> To unsubscribe from Zend Framework Community, click here.
>>> NAML
>>>
>>
>>
>>
>> --
>>  If you reply to this email, your message will be added to the
>> discussion below:
>>
>> http://zend-framework-community.634137.n4.nabble.com/Display-other-module-content-within-module-in-zend-framework-2-tp4660968p4660972.html
>>  To unsubscribe from Display other module content within module in zend
>> framework 2, click here.
>> NAML
>>
>
>
>
> --
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://zend-framework-community.634137.n4.nabble.com/Display-other-module-content-within-module-in-zend-framework-2-tp4660968p4660979.html
>  To start a new topic under Zend Framework, email
> ml-node+s634137n634138...@n4.nabble.com
> To unsubscribe from Zend Framework Community, click 
> here
> .
> NAML
>




--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/Display-other-module-content-within-module-in-zend-framework-2-tp4660968p4660982.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Re: [fw-general] Re: AbstractRestfulController not found resource best way

2013-09-15 Thread Marco Pivetta
I prefer throwing a new `NotFoundException` and then using an exception
strategy to transform it into whatever kind of output you want :)

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/


On 15 September 2013 21:29, whisher  wrote:

> samsonasik wrote
> > hm.., maybe like this ?
> >
> > $this->getResponse()->setStatusCode(404);
> > $this->getResponse()->setContent(json_encode(array(
> > 'status'  => $this->getResponse()->getStatusCode(),
> > 'error'   =>'Not Found',
> > 'message' => 'Page not found.'
> > )));
> > $this->getResponse()->getHeaders()
> >  ->addHeaderLine('content-type', 'application/json');
> >
> > return $this->getResponse();
>
> hm... not very clean (I'd like use JsonModel) but if I don't found any
> other
> way ^^
>
>
>
> --
> View this message in context:
> http://zend-framework-community.634137.n4.nabble.com/AbstractRestfulController-not-found-resource-best-way-tp4660975p4660980.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
> --
> List: fw-general@lists.zend.com
> Info: http://framework.zend.com/archives
> Unsubscribe: fw-general-unsubscr...@lists.zend.com
>
>
>


[fw-general] Re: AbstractRestfulController not found resource best way

2013-09-15 Thread whisher
samsonasik wrote
> hm.., maybe like this ?
> 
> $this->getResponse()->setStatusCode(404); 
> $this->getResponse()->setContent(json_encode(array(
> 'status'  => $this->getResponse()->getStatusCode(),
> 'error'   =>'Not Found',
> 'message' => 'Page not found.' 
> )));
> $this->getResponse()->getHeaders()
>  ->addHeaderLine('content-type', 'application/json');
> 
> return $this->getResponse();

hm... not very clean (I'd like use JsonModel) but if I don't found any other
way ^^



--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/AbstractRestfulController-not-found-resource-best-way-tp4660975p4660980.html
Sent from the Zend Framework mailing list archive at Nabble.com.

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




[fw-general] Re: Display other module content within module in zend framework 2

2013-09-15 Thread facCoder
Thanks for your reply...

Basically, when I call the controller's action(method) of another module,
it rendered its layout. I want this layout to be render on current layout
as partial layout. i.e. on particular div i want to render this layout.

Is it possible???


On Sun, Sep 15, 2013 at 6:35 AM, Marco Pivetta [via Zend Framework
Community]  wrote:

> Layouts are just named scripts (the names are used by the view resolver to
> find out what the path to the script is).
>
> There's two ways to achieve what you want to do:
>
>  1 - use the `layout` controller helper
>  2 - modify the view model contained in your application's MvcEvent
> (->getViewModel()) so that the template name corresponds to the layout you
> want.
>
>
> Marco Pivetta
>
> http://twitter.com/Ocramius
>
> http://ocramius.github.com/
>
>
> On 14 September 2013 20:58, facCoder [via Zend Framework Community] <[hidden
> email] > wrote:
>
>> I am new to zend framework 2. I want to display other module
>> contents(layout) within module.
>>
>> Means i am in abc module and x layout is rendered. On click to anchor tag
>> i want to show other module layout in abc moudule x layout.
>>
>> Similar to partial layouts.
>>
>>
>> --
>>  If you reply to this email, your message will be added to the
>> discussion below:
>>
>> http://zend-framework-community.634137.n4.nabble.com/Display-other-module-content-within-module-in-zend-framework-2-tp4660968.html
>>  To start a new topic under Zend Framework, email [hidden 
>> email]
>> To unsubscribe from Zend Framework Community, click here.
>> NAML
>>
>
>
>
> --
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://zend-framework-community.634137.n4.nabble.com/Display-other-module-content-within-module-in-zend-framework-2-tp4660968p4660972.html
>  To unsubscribe from Display other module content within module in zend
> framework 2, click 
> here
> .
> NAML
>




--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/Display-other-module-content-within-module-in-zend-framework-2-tp4660968p4660979.html
Sent from the Zend Framework mailing list archive at Nabble.com.

[fw-general] Zend\Sql\TableGateway|Where|Predicate bug?

2013-09-15 Thread András Csányi
Hi All,

I put together my application and I use TableGateway pattern based on
the tutorial. I got some help how to select data from the database if
there are multiple where conditions. It is quite good and easy when
you got the way how it works.

Unfortunately, I found something interesting:

I have this code in one of my tablegateway class:

public function selectWith($select = null) {

$filter = new Predicate();
$filter->like('category_name',"%dess%")
->OR
->like('category_desc', "%ks%");

var_dump($this->tableGateway->select(function(Select $select)
use ($filter) {
$select->where($filter);
}));

return $this->tableGateway->select(function(Select $select)
use ($filter) {
$select->where($filter);
});
}

According to the dump the executed select is the following:

'SELECT `categories`.* FROM `categories` WHERE (`category_name` LIKE
:where1 OR `category_desc` LIKE :where2)'

But it should be this:

SELECT `categories`.* FROM `categories` WHERE (`category_name` LIKE
'%dess%' OR `category_desc` LIKE '%ks%')

The result is the same if I use Where instead of Predicate.

I use ZF 2.2.2.

Is this a known issue or I did something wrong?

Thanks for any help in advance!

András


-- 
--  Csanyi Andras (Sayusi Ando)  -- http://sayusi.hu --
http://facebook.com/andras.csanyi
--  ""Trust in God and keep your gunpowder dry!" - Cromwell

--
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




[fw-general] Re: TableGateway and multiple where conditions in a select

2013-09-15 Thread András Csányi
I got this as an answer, I hope it may help for others.

Hello Andras,

Just saw you message
Didn't want to clutter the list with the reply...

Simply there is addPredicate internal mechanism used in those classes
You've got to pass a filter to select closure then apply it in the
closure body...

Try this:
$filter =  new Zend\Db\Sql\Predicate\Predicate();
$filter->equalTo('fielda',5)->and->lessThan('fieldb',4);
$limit = 1000;
$orderseq = array('name'=>'DESC','number'=>'ASC');
$this->tableGateaway->select(function(Select $select) use
($filter,$limit,$orderseq){
$select->where($filter);
$select->limit($limit);
$select->order($orderseq);
});

More details here:
https://github.com/zendframework/zf2/blob/master/library/Zend/Db/Sql/Predicate/Predicate.php

It's quite obvious how it is realized in ZF2:
https://github.com/zendframework/zf2/blob/master/library/Zend/Db/TableGateway/AbstractTableGateway.php
(skip down to select() function signature).

Any questions - will be happy to help...

Best regards, Konstantin

Best regards,
Konstantin

On 14 September 2013 19:40, András Csányi  wrote:
> Hi All,
>
> I implemented the TableGateway pattern based-on the tutorial, but I
> don't know how to select data from the database when the where is
> complicated. I went through the reference but I did not found anything
> useful. On the other hand, I did not find any help in the
> documentation about how is possible to use Select and Sql objects, If
> I recall correctly then in ZF1 it was possible to use these object to
> put together the query.
>
> So, I would like to execute a query which looks like this:
>
> "SELECT column1, column2, column3 FROM table WHERE column_z like
> '%string%' AND column_f like '%string2%'"
>
> The point of the whole is that there are multiple where conditions.
>
> If you know a blog where it is described or an article somewhere I
> would be very happy!
>
> Thanks for any help in advance!
>
> András
>
> --
> --  Csanyi Andras (Sayusi Ando)  -- http://sayusi.hu --
> http://facebook.com/andras.csanyi
> --  ""Trust in God and keep your gunpowder dry!" - Cromwell



-- 
--  Csanyi Andras (Sayusi Ando)  -- http://sayusi.hu --
http://facebook.com/andras.csanyi
--  ""Trust in God and keep your gunpowder dry!" - Cromwell

--
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




[fw-general] AbstractRestfulController not found resource best way

2013-09-15 Thread whisher
Hi,
-I'm wondering what's the best way
1)
public function get($id)
{
$entity = $this->getMapper()->fetchById($id);
if(is_bool($entity) && !$entity){
return $this->getResponse()->setStatusCode(404); 
}
return new JsonModel(array(
   'status'=>200,
'data' => $entity->toArray()
 )
));
}
2)
public function get($id)
{
$entity = $this->getMapper()->fetchById($id);
if(is_bool($entity) && !$entity){
$this->getResponse()->setStatusCode(404);
return new JsonModel(array(
array(
'status' => 404,
'error'=>'Not Found')
));
}
return new JsonModel(array(
array(
'status'=>200,
'data' => $entity->toArray()
)
));
}

-Is it possible manage it by the model ?
-Is there a way to avoid this
{"0":{"status":404,"error":"Not Found"},"message":"Page not
found.","reason":"error-controller-cannot-dispatch","display_exceptions":true,"controller":"FbswitRest\\Controller\\PhotoController","controller_class":null}
an get only
[{"status":404,"error":"Not Found"},"message":"Page not found."}]

Thanks in advance.





--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/AbstractRestfulController-not-found-resource-best-way-tp4660975.html
Sent from the Zend Framework mailing list archive at Nabble.com.

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com




[fw-general] PHPUnit Routing Error

2013-09-15 Thread Jigal sanders
Hello Everyone,

I am running on the latest version of the ZF 2.2.4

I have the following route:

  'overview'  => array(
'type' => 'Segment',
'options' => array(
'route' => '/overview[/productgroup/:productgroup]',
'defaults' => array(
'__NAMESPACE__' => 'MyApp\Controller',
'controller' => 'Overview',
'action'=> 'index',
),
),
'may_terminate' => true,
),

Now in my controller i want to test that i can acces the overview route


 public function setUp(){

$serviceManager = ServiceManagerFactory::getServiceManager();
$this->controller   = new OverviewController();
$this->request  = new Request();
$this->routeMatch   = new RouteMatch(array('controller' =>
'overview'));
$this->event= new MvcEvent();

$config = $serviceManager->get('Config');
$routerConfig = isset($config['router']) ? $config['router'] :
array();
$router = HttpRouter::factory($routerConfig);

$this->event->setRouter($router);
$this->event->setRouteMatch($this->routeMatch);
$this->controller->setEvent($this->event);
$this->controller->setServiceLocator($serviceManager);
}

public function testIndexActionCanBeAccessed(){
$this->routeMatch->setParam('action', 'index');

$response = $this->controller->getResponse();
$this->assertEquals(200, $response->getStatusCode());
}

But I get this error:


1) MyAppTest\Controller\OverviewControllerTest::testIndexActionCanBeAccessed
Zend\Mvc\Router\Exception\InvalidArgumentException: Missing "type" option

C:\wamp\www\MyApp\vendor\zendframework\zendframework\library\Zend\Mvc\Router\
SimpleRouteStack.php:269
C:\wamp\www\MyApp\vendor\zendframework\zendframework\library\Zend\Mvc\Router\
Http\TreeRouteStack.php:159
C:\wamp\www\MyApp\vendor\zendframework\zendframework\library\Zend\Mvc\Router\
Http\TreeRouteStack.php:113
C:\wamp\www\MyApp\vendor\zendframework\zendframework\library\Zend\Mvc\Router\
SimpleRouteStack.php:140
C:\wamp\www\MyApp\vendor\zendframework\zendframework\library\Zend\Mvc\Router\
SimpleRouteStack.php:84
C:\wamp\www\MyApp\vendor\zendframework\zendframework\library\Zend\Mvc\Router\
Http\TreeRouteStack.php:65
C:\wamp\www\MyApp\module\MyApp\test\MyAppTest\Controller\OverviewContro
llerTest.php:45
C:\wamp\bin\php\php5.3.9\pear\PHPUnit\TextUI\Command.php:176
C:\wamp\bin\php\php5.3.9\pear\PHPUnit\TextUI\Command.php:129


The error says that i Miss the type option. But if you look at the route
you see there is a type option. What could be wrong?


Thanks

-- 


Jigal Sanders