Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Oct 14 17:04

    nicksagona on 4.5.10

    (compare)

  • Oct 14 17:03

    nicksagona on 4.5.10

    (compare)

  • Oct 14 17:02

    nicksagona on v4-dev

    Patch dirty save (compare)

  • Oct 14 16:57

    nicksagona on master

    Patch dirty save/set function (compare)

  • Oct 14 16:57

    nicksagona on v5-dev

    Patch dirty save/set function (compare)

  • Aug 18 16:37
    nicksagona closed #23
  • Aug 18 16:37

    nicksagona on 3.6.1

    (compare)

  • Aug 18 16:36

    nicksagona on master

    Patch setValue issue with Check… (compare)

  • Aug 18 16:35

    nicksagona on v3-dev

    Patch setValue issue with Check… (compare)

  • Aug 12 14:54
    B0bbyD0llar opened #23
  • Apr 14 17:34

    nicksagona on 5.3.1

    (compare)

  • Apr 14 17:28

    nicksagona on master

    Add support for column select o… (compare)

  • Apr 14 17:25

    nicksagona on v5-dev

    Add support for column select o… (compare)

  • Feb 12 23:35

    nicksagona on 3.6.0

    (compare)

  • Feb 12 23:34

    nicksagona on v3-dev

    Update workflow (compare)

  • Feb 12 23:34

    nicksagona on master

    Update workflow (compare)

  • Feb 12 23:32

    nicksagona on master

    Update version and copyright (compare)

  • Feb 12 23:32

    nicksagona on v3-dev

    Update version and copyright (compare)

  • Feb 12 22:26

    nicksagona on 3.4.0

    (compare)

  • Feb 12 22:25

    nicksagona on master

    Update version and copyright (compare)

Nick Sagona
@nicksagona
public function profile($id)
{
    echo $id;
}
the router itself would not be aware of any set of potential routes (/profile/1, /profile/2, etc.) that are available in the system. It's simply reactive to all requests coming through and handles the logic to figure out if the route is a valid route or not and which controller/action to hand it off to. It would just know that any route of /profile/:id is valid and to pass it off to the controller from there
Let me know if that helps any. Thanks!
petkovic-v
@petkovic-v

Yes, Mr. Nick that's what I want to achieve as an output Html. I apologize in advance for my poor knowledge of English and if it bothers you to clearly understand what I want to ask.

However, if I may say so, you are hard coding the url in the foreach loop (at least as far as the url part /profile/ is concerned) and this is considered bad practice.Why?

I'm actually interested in something called "bidirectional routing"

here is some definition :

"Thanks to bidirectional routing, you'll never have to hardcode application's URLs in the templates(Views) or code, which may change later or be complicated to compose. Just specify the Controller name and the action name , pass any parameters (for genereting dynamic segments url and query string variable) and the framework (Laravel , Slim ....) will generate the URL itself. "

The point is that urls not recommended creating by hard coding (like a string - href ="myWebApp/segment1/segment2?var1=1") because if for some reason a url needs to be changed and if that url address is used in 20 places in a web application, it is a very tedious job prone to errors.

therefore, bidirectional routing (as far as I understand) allows us to define route and url string (url templates) and also we can define which controller and its action method will react to that url address.(this is how routes are defined in all mvc frameworks, and in POPPhp also).

But in Laravel and Slim,continue on, and we can give each route a name. Why is the name important?

In Laravel, for example, there is a function route() which accepts two parameters: the name of the route (The name is used to access the route) and options array.In options array we can define parameters for dynamic route segments and for the query string variable.the route function automatically generates and returns a url string relative to the arguments passed to it.

example :

Route::get('/post/{post}', function () {
    //
})->name('post.show');

To generate a URL to this route, you may use the route helper like so:

echo route('post.show', ['post' => 1]);

// http://example.com/post/1   - genereting concrete url string

In this way, in Laravel, we MUST hard coding the url address ONLY IN ONE PLACE - in the route definition and if we now need to use that ulr address in, say, 20 places in a web application, then instead of using a hard-coded url string, we call the route (routeName, opt) function in 20 places, which will generate the url string, given the arguments passed (for example id is read from the database and used in foreach loop to generate).

If the url needs to be changed tomorrow for any reason, it only needs to be changed in one place (in the route definition) and that change will be automatically reflected in all 20 places in the application.

So, ...
Is there such a function in the popphp framework that we pass the name of the controller , the name of the action method of the controller and parameters (for dynamic url segments and variable of the query string) and that function then generates and returns the url string address?
If POPPHP had a route name property, then neither the name of the controller, nor the name of its method would have to be passed to route() function , but only the name of the route because the name of the controller and its methods are automatically read from the route definition.

Nick Sagona
@nicksagona
ok I understand what your asking about. You're asking about URL generation (from the router)
and at this time, that is not available, but is definitely something that can be considered.
petkovic-v
@petkovic-v
Yes, that's right. Thank you for all the answers.
Nick Sagona
@nicksagona
No problem. Like I said, we can consider adding this functionality.
Nick Sagona
@nicksagona
@petkovic-v okay, I've got a quick proof of concept up and running for URL generation coming from the Router component in the core popphp repo
if you want, you can check the repo out and checkout to the v3-dev-7 branch and see what's going on.
A quick run down on how it's working initially
you can add named routes either programmatically or via the application route config:
option 1:
$router = new Pop\Router\Router();

$router->addRoute('/home', function() {
    echo 'Home!' . PHP_EOL;
})->name('home');

$router->addRoute('/hello/:name', function($name) {
    echo 'Hello, ' . $name . '!' . PHP_EOL;
})->name('hello');
option 2:
$app = new Application([
    'routes' => [
        '/home' => [
            'controller' => function () {
                echo 'Home!' . PHP_EOL;
            },
            'name' => 'home'
        ],
        '/hello/:name' => [
            'controller' => function ($name) {
                echo 'Hello, ' . $name . '!' . PHP_EOL;
            },
            'name' => 'hello'
        ]
    ]
]);
either should work the same
there is also now a global/static Route class that acts like a custom service container of the router object for the application. With that, anywhere in the application you can do this:
(this works with arrays or objects)
$nick = new stdClass();
$nick->name = 'nick';

$jim = new stdClass();
$jim->name = 'jim';

$world = new stdClass();
$world->name = 'world';

$names = [$nick, $jim, $world];

foreach ($names as $name) {
    echo '<a href="' . Route::url('hello', $name) . '">'  .  $name['name'] . '</a>';
}
and that should generate:
Nick Sagona
@nicksagona
<a href="/hello/nick">nick</a>
<a href="/hello/jim">jim</a>
<a href="/hello/world">world</a>
petkovic-v
@petkovic-v

Yes, that's what we need, Nick.

Route :: url (nameOfRoute, Parameters)

Thank you so much for your efforts to resolve this.

Nick Sagona
@nicksagona
ok great. if this provides everything you were looking for in this feature, I'll go ahead and merge it into master and cut a release a little later on today. Thanks for your input on this.
Nick Sagona
@nicksagona
Ok the new named routes and URL generation features have been released under the popphp 3.6.0 release. The docs have been updated as well.
Nick Sagona
@nicksagona
Hey everyone - quick announcement for an added feature to pop-db
Relationships now support nested/child relationships via a dot notation:
$user = Users::with('posts.comments')->getById(1001);
you can read more about it under the docs here (under Eager-loading) https://pop-php-framework.readthedocs.io/en/latest/user_guide/databases.html#relationships-associations
this is available in pop-db v5.2.0
Thirdman Works Corporation
@ThirdmanC_twitter
hello Guys, am having issues using kettle from command line (Windows)
Nick Sagona
@nicksagona
hello - so what issues are you having?
DrewM
@AndrewM
I'm having a hard time figuring out how to simply align center in Pop PDF. The docs don't seem to cover anything about alignment.
Nick Sagona
@nicksagona
Hey Drew - apologies for that. That area of the docs haven't been updated. There are alignment and wrap features for Pop PDF. Here's an example of how to do an align center:
use Pop\Pdf\Pdf;
use Pop\Pdf\Document;
use Pop\Pdf\Document\Font;
use Pop\Pdf\Document\Page;

// Create text object
$string = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec ligula ligula. Cras at dictum nibh. Nulla pulvinar accumsan arcu vitae vulputate. Cras pretium libero sit amet lobortis sagittis. Aliquam interdum vitae eros ut porttitor. Sed maximus purus vitae metus euismod imperdiet. Aliquam varius ultrices augue ut consequat. Aliquam feugiat ipsum eleifend ipsum vulputate feugiat. In posuere velit id magna porta viverra. Morbi diam mauris, porta eget felis ac, tincidunt malesuada dui. Donec vel urna id elit egestas vestibulum eget ac erat.';
$text   = new Page\Text($string, 12);

// Add bounding alignment object 
$text->setAlignment(Page\Text\Alignment::createCenter(50, 562, 15));

// Create a page and add the text to it
$page = new Page(Page::LETTER);
$page->addText($text, Font::ARIAL, 50, 650);

// Create a document, add the font to it and then the page
$document = new Document();
$document->addFont(new Font(Font::ARIAL));
$document->addPage($page);

// Pass the document to the Pdf object to build it and output it to HTTP
$pdf = new Pdf();
$pdf->outputToHttp($document);
so the 3 params for the following line of code:
$text->setAlignment(Page\Text\Alignment::createCenter(50, 562, 15));
are $leftX, $rightX, and $leading
and those set the left and right bounds for the string of text to be contained and centered in.
document.pdf
That's the PDF that was created with that code sample. Let me know if that helps.
DrewM
@AndrewM
Yes, that helps! Thanks.
Nick Sagona
@nicksagona
Great! No problem. I'll try to carve out some time soon to update the docs to demo how the alignment and wrap features work for Pop PDF
FYI, if interested, there's also some experimental DOM/HTML rendering features in Pop PDF as well, but that needs a bit of work to be finished off (namely, I left off working on rendering tables)
DrewM
@AndrewM
Are there controls for a header/footer on every page with Pop PDF?
And lastly (I think).... what happened to the direct download of the latest versions of Pop PHP Framework? The website references links...but I cannot find a full-source download anywhere.
Nick Sagona
@nicksagona
so to answer the first question, there is nothing directly available for controlling headers/footers in Pop PDF at this time. It's something that could be considered, if kept pretty simple. But the main concern would be that it's something like that would be fairly specific/custom to the PDF you're looking to generate. I've handled it in my own applications by writing a little helper method that would generate all of the header and footer content formatted exactly as I need it to be. But they were fairly complex headers and footers with multiple lines of text, page numbers, images, etc.
And your second question is that, the decision was made about a year ago or so to no longer support or provide to direct download option. It was just one more thing to manage and the stats showed just about everyone using composer these days, so it seemed like a good time to do away with it. Using composer should be the preferred way to get Pop and/or any of its supporting components.
Nick Sagona
@nicksagona
Ah - I've corrected the docs that reference the stand-alone download. That's been removed as it is no longer supported.
Sorry for the confusion there.
Gideon Dannang
@gcd445_twitter
hi , is there an updated pop-bootstrap, or a project w/ pop-auth and pop-acl?