Asked  7 Months ago    Answers:  5   Viewed   33 times

I would like to do a simple INNER JOIN between two tables in Zend2.

Concretely, I would like to do this in Zend2:

SELECT * FROM foo, bar WHERE foo.foreign_id =;

I have a FooTable:

class FooTable
  protected $tableGateway;

  public function __construct(TableGateway $tableGateway)
    $this->tableGateway = $tableGateway;

  public function get($id)
    $rowset = $this->tableGateway->select(function (Select $select) {

The $select->from('foo'); returns an error:

==> Since this object was created with a table and/or schema in the constructor, it is read only.

So, I can't tweak my FROM statement to match a simple inner join between FooTable and BarTable.



I hope this will help you along your journey as this is a working example I have:

namespace PoolModel;

use ZendDbTableGatewayAbstractTableGateway;
use ZendDbSqlSelect;

class IpaddressPool extends AbstractTableGateway
    public function __construct($adapter)
        $this->table = 'ipaddress_pool';

        $this->adapter = $adapter;


    public function Leases($poolid)
        $result = $this->select(function (Select $select) use ($poolid) {
                ->join('account', 'account.accountid = ipaddress_pool.accountid', array(
                ->join('product_hosting', 'product_hosting.hostingid = ipaddress_pool.hostingid', array(
                ->join('webaccount', 'webaccount.webaccountid = ipaddress_pool.webaccountid', array(
                ))->where->equalTo('ipaddress_pool.poolid', $poolid);

        return $result->toArray();
Wednesday, March 31, 2021
answered 7 Months ago

As @Aydin Hassan commented, I've tried with:

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$excelOutput = ob_get_clean();

And then simply passed $excelOutput to the response content, and it works simply great!

Saturday, May 29, 2021
answered 5 Months ago

CakePHP's AuthComponent only supports authentication against a single "User" model at a time. The model is chosen by setting the Auth::userModel property, but it only accepts a string and not an array of models.

You can switch the userModel on the fly with the following code, but this requires you to know in advance which model to switch to (eg. your users have to choose their account type from a dropdown):

public function beforeFilter() {
    if (isset($this->data['User']['model'])) {
        $this->Auth->userModel = $this->data['User']['model'];

You can likely extend the core AuthComponent to add the functionality you want by overwriting the AuthComponent::identify() method so it loops over and attempts authentication with each model:

App::import('Component', 'AuthComponent');
class AppAuthComponent extends AuthComponent {

    function identify($user = null, $conditions = null) {
        $models = array('User', 'Admin', 'Artist', 'TeamAdmin');
        foreach ($models as $model) {
            $this->userModel = $model; // switch model
            $result = parent::identify($user, $conditions); // let cake do it's thing
            if ($result) {
                return $result; // login success
        return null; // login failure

You will have to replace occurrences of Auth in your application with AppAuth to use your extended AuthComponent, unless you use this trick.

Monday, June 28, 2021
answered 4 Months ago

I forgot to answer my own question when I figured it out I apologize to the community that I forgot... but for everyones benefit here is how I got it to work.


<target name="phpunit" description="Run unit tests with PHPUnit">
    <apply executable="../vendor/bin/phpunit" parallel="false">
        <fileset dir="${env.WORKSPACE}/module" >
            <include name="**/test/phpunit.xml"/>
        <arg value="--configuration" />

And the phpunit.xml for each module

<phpunit bootstrap="Bootstrap.php">
        <testsuite name="Application">

<!-- Filters only matter for code coverage reporting -->
        <log type="coverage-html" target="../../../build/coverage" title="Application Module" charset="UTF-8" yui="true" highlight="true" lowUpperBound="35" highLowerBound="70"/>
        <log type="coverage-clover" target="../../../build/logs/clover-Application.xml"/>
        <log type="junit" target="../../../build/logs/junit-Application.xml" logIncompleteSkipped="false"/>
Thursday, July 29, 2021
answered 3 Months ago

I found it out with the help of this Use one Laravel migrations table per database and post the answer here for others.

In order to separate the migrations you need to run the migrate command with the database option like this:

php artisan migrate --database="nameOfConnection"
Tuesday, September 21, 2021
answered 1 Month ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :