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 = bar.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) {
      $select->from('foo');
    });
  }
}

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.

 Answers

14

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;

        $this->initialize();
    }

    public function Leases($poolid)
    {
        $result = $this->select(function (Select $select) use ($poolid) {
            $select
                ->columns(array(
                    'ipaddress',
                    'accountid',
                    'productid',
                    'webaccountid'
                ))
                ->join('account', 'account.accountid = ipaddress_pool.accountid', array(
                    'firstname',
                    'lastname'
                ))
                ->join('product_hosting', 'product_hosting.hostingid = ipaddress_pool.hostingid', array(
                    'name'
                ))
                ->join('webaccount', 'webaccount.webaccountid = ipaddress_pool.webaccountid', array(
                    'domain'
                ))->where->equalTo('ipaddress_pool.poolid', $poolid);
        });

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

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

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
ob_start();
$objWriter->save('php://output');
$excelOutput = ob_get_clean();

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

$response->setContent($excelOutput);
Saturday, May 29, 2021
 
PHLAK
answered 5 Months ago
18

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
 
erotsppa
answered 4 Months ago
27

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.

build.xml

<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"/>
        </fileset>
        <arg value="--configuration" />
        <srcfile/>
    </apply>
</target>

And the phpunit.xml for each module

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

<!-- Filters only matter for code coverage reporting -->
    <filter>
        <blacklist>
            <directory>../../../vendor/</directory>
            <directory>./</directory>
            <file>../Module.php</file>
        </blacklist>
    </filter>
    <logging>
        <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"/>
    </logging>
</phpunit>
Thursday, July 29, 2021
 
QuantumMechanic
answered 3 Months ago
85

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
 
clean_coding
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 :
 
Share