(Ebook) Yii Application Development Cookbook - Second Edition by Alexander Makarov ISBN 9781782163107, 1782163107 instant download
(Ebook) Yii Application Development Cookbook - Second Edition by Alexander Makarov ISBN 9781782163107, 1782163107 instant download
https://ebooknice.com/product/yii-application-development-
cookbook-second-edition-4544506
https://ebooknice.com/product/yii2-application-development-cookbook-6857864
https://ebooknice.com/product/web-application-development-with-yii-and-php-
second-edition-43137684
https://ebooknice.com/product/boost-c-application-development-cookbook-
second-edition-recipes-to-simplify-your-application-development-55094592
https://ebooknice.com/product/android-application-development-cookbook-
second-edition-2016-57645008
(Ebook) Play Framework Cookbook - Second edition by Alexander
Reelsen, Giancarlo Inductivo ISBN 9781784393137, 1784393134
https://ebooknice.com/product/play-framework-cookbook-second-
edition-5210522
https://ebooknice.com/product/wxpython-2-8-application-development-
cookbook-2433768
https://ebooknice.com/product/pyside-gui-application-development-second-
edition-5317732
https://ebooknice.com/product/javafx-1-2-application-development-
cookbook-1756682
https://ebooknice.com/product/introducing-play-framework-java-web-
application-development-second-edition-24685646
Yii Application
Development
Cookbook
Second Edition
Alexander Makarov
BIRMINGHAM - MUMBAI
Yii Application Development Cookbook
Second Edition
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, without the prior written permission of the publisher,
except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the
information presented. However, the information contained in this book is sold without
warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers
and distributors will be held liable for any damages caused or alleged to be caused directly
or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies
and products mentioned in this book by the appropriate use of capitals. However, Packt
Publishing cannot guarantee the accuracy of this information.
ISBN 978-1-78216-310-7
www.packtpub.com
Reviewers Proofreaders
Maurizio Domba Maria Gould
Thomas Jantz Paul Hindle
Lawrence A. Herman
Acquisition Editor
Usha Iyer Indexer
Hemangini Bari
Lead Technical Editor
Joel Noronha Graphics
Ronak Dhruv
Technical Editors
Hardik B. Soni Production Coordinator
Ankita Meshram Nilesh R. Mohite
Cover Work
Nilesh R. Mohite
About the Author
Alexander Makarav is an experienced engineer from Russia and has been a Yii
framework core team member since 2010. Before joining the Yii core team, he participated
in the CodeIgniter community growth in Russia. In 2009, he finished the Russian translation
of the framework documentation and created the Russian community website. In 2012, he
released the Russian version of the book along with Russian community members. In the
same year, he was the technical reviewer for three more books:
ff The Yii Book: Developing Web Applications Using the Yii PHP Framework,
Larry Ullman
ff Web Application Development with Yii and PHP, Jeff Winesett
ff Yii Rapid Application Development Hotshot, Lauren O'Meara and James Hamilton
Maurizio Domba is a frontend and backend web developer with over 20 years of
professional experience in computer programming and 10 years in web development.
He is part of the Yii core development team since August 2010 and is an active member
of the Yii community.
At the moment he is developing intranet web applications for an export-import enterprise and
working on other international projects, always trying to help others to improve their code and
project usability.
When not programming the Web, he is programming his wife and kids, always with a smile on
his face, open-hearted and open-minded. He loves climbing, martial arts, meditation,
and salsa.
Thomas Jantz brings his background in language and art to his career as a web application
development consultant at Plum Flower Software. His projects include an emphasis on rapid
application development and user experience.
www.PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF and ePub
files available? You can upgrade to the eBook version at www.PacktPub.com and as a print
book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
service@packtpub.com for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up
for a range of free newsletters and receive exclusive discounts and offers on Packt books and
eBooks.
TM
http://PacktLib.PacktPub.com
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book
library. Here, you can access, read and search across Packt's entire library of books.
Why Subscribe?
ff Fully searchable across every book published by Packt
ff Copy and paste, print and bookmark content
ff On demand and accessible via web browser
ii
Table of Contents
Using lists 214
Creating custom grid columns 219
Chapter 8: Extending Yii 225
Introduction 225
Creating model behaviors 226
Creating components 232
Creating reusable controller actions 236
Creating reusable controllers 239
Creating a widget 243
Creating CLI commands 245
Creating filters 249
Creating modules 251
Creating a custom view renderer 258
Making extensions distribution-ready 263
Chapter 9: Error Handling, Debugging, and Logging 267
Introduction 267
Using different log routes 267
Analyzing the Yii error stack trace 274
Logging and using the context information 277
Implementing your own smart 404 handler 281
Chapter 10: Security 287
Introduction 287
Using controller filters 287
Using CHtml and CHtmlPurifier to prevent XSS 292
Preventing SQL injections 296
Preventing CSRF 301
Using RBAC 305
Chapter 11: Performance Tuning 313
Introduction 313
Following best practices 313
Speeding up session handling 317
Using cache dependencies and chains 321
Profiling an application with Yii 327
Leveraging HTTP caching 337
Chapter 12: Using External Code 343
Introduction 343
Using Zend Framework from Yii 343
Customizing the Yii autoloader 348
Using Kohana inside Yii 353
iii
Table of Contents
Using PEAR inside Yii 361
Using Composer with Yii 363
Chapter 13: Deployment 367
Introduction 367
Changing the Yii directory layout 367
Moving an application out of webroot 370
Sharing the framework directory 372
Moving configuration parts into separate files 374
Using multiple configurations to simplify the deployment 378
Implementing and executing cron jobs 381
Maintenance mode 383
Index 387
iv
Preface
Yii is a very flexible and high-performance application development framework written in
PHP. It helps building web applications, from small to large-scale enterprise applications.
The framework name stands for Yes It Is (Yii). This is often the accurate and most concise
response to inquiries from those new to Yii such as: Is it fast? Is it secure? Is it professional?
Is it right for my next project? But the answer is an unequivocal, yes it is!
This cookbook contains 13 independent chapters full of recipes that will show you how to use
Yii efficiently. You will learn about the hidden framework gems, using core features, creating
your own reusable code base, using test-driven development, and many more topics that will
bring your knowledge to a whole new level!
Chapter 2, Router, Controller, and Views, is about handy things concerning the Yii URL
router, controllers, and views: URL rules, external actions and controllers, view clips,
decorators, and more.
Chapter 3, AJAX and jQuery, focuses on the Yii's client side that is built with jQuery—the most
widely used JavaScript library out there. It is very powerful and easy to learn and use. This
chapter focuses on Yii-specific tricks rather than jQuery itself.
Chapter 4, Working with Forms, shows how Yii makes working with forms a breeze and
documentation on it is almost complete. Still, there are some areas that need clarification
and examples. Some of the topics covered in this chapter are creating validators and input
widgets, uploading files, and using and customizing CAPTCHA.
Chapter 5, Testing Your Application, covers unit testing, functional testing, and generating
code coverage reports. Recipes follow a test-driven development approach. You will write tests
for several small applications and then implement functionality.
Preface
Chapter 6, Database, Active Record, and Model Tricks, is about working with databases
efficiently, when to use models and when not to, how to work with multiple databases, how to
automatically pre-process Active Record fields, and how to use powerful database criteria.
Chapter 7, Using Zii Components, covers data providers, grids, and lists: How to configure
sorting and searching, how to use grids with multiple related models, how to create your own
column types, and more.
Chapter 8, Extending Yii, shows not only how to implement your own Yii extension but also
how to make your extension reusable and useful for the community. In addition, we will focus
on many things you should do to make your extension as efficient as possible.
Chapter 9, Error Handling, Debugging, and Logging, reviews logging, analyzing the exception
stack trace, and own error handler implementation.
Chapter 10, Security, provides information about keeping your application secure according
to the general web application security principle "filter input, escape output." We will cover
topics such as creating your own controller filters, preventing XSS, CSRF, and SQL injections,
escaping output, and using role-based access control.
Chapter 11, Performance Tuning, shows how to configure Yii to gain extra performance. You
will learn a few best practices for developing an application that will run smoothly until you
have very high loads.
Chapter 12, Using External Code, focuses on using third-party code with Yii. We will use
Zend Framework, Kohana, and PEAR but you will be able to use any code after learning
how it works.
Chapter 13, Deployment, covers various tips that are especially useful on application
deployment, when developing an application in a team, or when you just want to make your
development environment more comfortable.
ff Web server: The 2.x version of Apache web server is preferred. Other versions and
web servers will work too, but configuration details are not provided.
ff Database server: The database server that can be used is MySQL 4+ with InnoDB
support (MySQL 5 or higher is recommended).
ff PHP: The PHP 5.2 or PHP 5.3 version can be used (PHP 5.3 recommended).
ff Yii: The latest Yii version can be used (1.1.x is recommended).
2
Preface
Additionally, the following tools are not strictly required but are used for specific recipes:
ff PHPUnit
ff Xdebug
ff Selenium RC
ff PEAR
ff Smarty
ff memcached
Conventions
In this book, you will find a number of styles of text that distinguish between different kinds of
information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions,
pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "To declare
an event in your CComponent child class, you should add a method with a name starting
with on."
$yii=dirname(__FILE__).'/../framework/yii.php';
$config=dirname(__FILE__).'/../app/config/production.php';
require($yii);
Yii::createWebApplication($config)->run();
3
Preface
New terms and important words are shown in bold. Words that you see on the screen, in
menus or dialog boxes for example, appear in the text like this: "Now, go to the Gii controller
generator and enter SecureController into the Base Class field."
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this
book—what you liked or may have disliked. Reader feedback is important for us to develop
titles that you really get the most out of.
To send the author feedback about the book, simply fill in the form at
http://yiicookbook.org/feedback.
If there is a topic that you have expertise in and you are interested in either writing or
contributing to a book, see our author guide at www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you to
get the most from your purchase.
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes do
happen. If you find a mistake in one of our books—maybe a mistake in the text or the
code—we would be grateful if you would report this to us. By doing so, you can save other
readers from frustration and help us improve subsequent versions of this book. If you find any
errata, please report them by visiting http://yiicookbook.org/feedback, and entering
the details of your errata. Once your errata are verified, your submission will be accepted and
the errata will be uploaded on the book website at http://yiicookbook.org/errata.
4
Preface
Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt,
we take the protection of our copyright and licenses very seriously. If you come across any
illegal copies of our works, in any form, on the Internet, please provide us with the location
address or website name immediately so that we can pursue a remedy.
We appreciate your help in protecting our authors, and our ability to bring you
valuable content.
Questions
You can contact the book's author at http://yiicookbook.org/feedback. if you are
having a problem with any aspect of the book, and he will do his best to address it.
5
Under the Hood
1
In this chapter, we will cover:
Introduction
In this chapter, we will cover the most interesting Yii features that are hidden "under the
hood". These are mostly described in the framework API, but since they are not mentioned
in the official guide (http://www.yiiframework.com/doc/guide/) or only mentioned
very briefly, only experienced Yii developers usually use these. However, the features
described here are relatively simple and using them makes development with Yii much
more fun and productive.
From this recipe, you will learn how to define your own properties using getters and setters,
how to make your properties read-only, and how to hide custom processing behind native
PHP assignments.
How to do it...
1. As PHP does not have properties at the language level, we can only use getters and
setters in the following way:
class MyClass
{
// hiding $property
private $property;
// getter
public function getProperty()
{
return $this->property;
}
// setter
public function setProperty($value)
{
$this->property = $value;
}
}
// setting value
$object->setProperty('value');
// getting value
echo $object->getProperty();
2. This syntax is very common in the Java world but it is a bit long to use in PHP.
Still, we want to use the same functionality that C# properties gives us: calling
getters and setters like class members ($model->property instead of $model-
>getProperty()). With Yii, we can do it in the following way:
// extending CComponent is necessary
class MyClass extends CComponent
{
private $property;
8
Chapter 1
return $this->property;
}
3. Using this feature, you can make properties read-only or write-only while keeping the
simple PHP syntax as follows:
class MyClass extends CComponent
{
private $read = 'read only property';
private $write = 'write only property';
9
Random documents with unrelated
content Scribd suggests to you:
“Parade! Tchern!!” shouted Sergeant-Major Shandon; and a moment
later the four company commanders came to attention and saluted
as the Colonel passed in, sprinkling “Good mornings” to right and
left.
I had to pass from one end of the village to the other. The orderly-
room was not far from our company “Mess” and was at a cross-
roads. Opposite, in one of the angles made by the junction of the
four roads, was a deep and usually muddy horse-pond. But even
here the mud was getting hard under this spell of warm May
weather, and the innumerable ruts and hoof-marks were crystallising
into a permanent pattern. As I walked along the streets I passed
sundry Tommies acting as road-scavengers; “permanent road
fatigue” they were called, although they were anything but
permanent, being changed every day. Formerly they had seemed to
be engaged in a Herculean, though unromantic, task of scraping
great rolling puddings of mud to the side of the road, in the vain
hope that the mud would find an automatic exit into neighbouring
gardens and ponds; for Morlancourt did not boast such modern
things as gutters. To-day there were large pats of mud lining the
street, but these were now caked and hard, and even crumbling into
dust, that whisked about among the sparrows. The permanent road
fatigue was gathering waste-paper and tins in large quantities, but
otherwise was having a holiday.
“A great day, this,” I thought, as I came to the small field where “B”
Company was paraded; not two hundred and fifty men, as you will
doubtless assume from the text-books, but some thirty or forty men
only; one was lucky if one mustered forty. Where were the rest, you
ask? Well, bombers bombing; Lewis gunners under Edwards; some
on “permanent mining fatigue,” that is, carrying the sand-bags from
the mine-shafts to the dumps; transport, pioneers, stretcher-
bearers, men under bombing instruction, officers’ servants,
headquarter orderlies, men on leave, etc. etc. The company
sergeant-major will make out a parade slate for you if you want it,
showing exactly where every man is. But here are forty men. Let’s
drill them.
When both parties were duly exercised, I gave a short lecture on the
measures to be adopted against the use of Flammenwerfer, which is
the “Liquid Fire” of the official communiqués. I had just been to a
demonstration of this atrocity in the form of a captured German
apparatus, and my chief object in lecturing the men about it was to
make it quite clear that the flaming jets of burning gas cannot sink
into a trench, but, as a matter of fact, only keep level so long as
they are propelled by the driving power of the hose apparatus; as
water from a hose goes straight, and then curves down to the
ground, so gas, even though it be incandescent, goes straight and
then rises. In the trench you are unscathed, as we proved in the
demonstration, when they sprayed the flaming gas over a trench full
of men. Indeed, the chief effect of this flammenwerfer is one of
frightfulness, as the Germans cannot come over until the flames
have ceased. The men were rather inclined to gape at all this, but I
found the words had sunk in when I asked what should be done if
the enemy used this diabolical stuff against us. “Get down at the
bottom of the trench, sir, and as soon as they stop it, give the ——’s
’ell!”
The rest of the morning we spent “on the range,” which meant firing
into a steep chalk bank at a hundred yards. Targets and paste-pot
had been procured from the pioneers’ shop, and after posting a
couple of “look-out” men on either side, we started range practice.
The men are always keen about firing on the range, and it is really
the most interesting and pleasant part of the infantryman’s training.
I watched these fellows, hugging their rifle-butt into their shoulder,
and feeling the smooth wood against their cheeks; they wriggled
their bodies about to get a comfortable position; sometimes they
flinched as they fired and jerked the rifle; sometimes they pressed
the trigger as softly, as softly.... And gradually, carefully, we tried to
detect and eliminate the faults. Then we ended up with fifteen
rounds rapid in a minute. The “mad minute” it used to be called at
home. After which we fell the men in, and Paul marched them back
to the company “alarm post” outside the company office, where “B”
Company always fell in; while Owen, Nicolson, and I walked back
together.
II. Afternoon
“I still maintain,” said I, an hour later, as we finished lunch, “that
bully-beef, some sort of sauce or pickle, and salad, followed by
cheese, and ending with a cup of tea, is the proper lunch for an
officer. I don’t mind other officers having tinned fruit, though, if they
like it,” I added with a laugh.
Owen and Syme were newly joined officers for whom the sight of
tinned pears or apricots had not yet lost a certain glamour that
disappeared after months and months. They were just finishing the
pear course. Hence my last remark.
I lit a pipe and strolled out into the garden. This was undoubtedly an
ideal billet, and a great improvement on the butcher’s shop, where
they used always to be killing pigs in the yard and letting the blood
run all over the place. It was a long, one-storied house, set back
about fifty yards from the road; this fifty yards was all garden, and,
at the end, completely shutting off the road, was a high brick wall.
On each side of the garden were also high walls formed by the sides
of stables and outhouses; the garden was thus completely walled
round, and the seclusion and peace thus entrapped were a very
priceless possession to us.
The garden itself was full of life. There were box-bordered paths up
both sides and down the centre, and on the inner side of the paths
was an herbaceous border smelling very sweet of wallflowers and
primulas of every variety. Although it was still May, there were
already one or two pink cabbage-roses out; later, the house itself
would be covered with them; already the buds were showing yellow
streaks as they tried to burst open their tight green sheaths. In the
centre of the garden ran a cross path with a summer-house of
bamboo canes completely covered with honeysuckle; that, too, was
budding already. The rest of the garden was filled with rows of
young green things, peas, and cabbages, and I know not what,
suitably protected against the ravages of sparrows and finches by
the usual miniature telegraph system of sticks connected by cotton
decorated with feathers and bits of rag. Every bit of digging, hoeing,
weeding and sowing were performed by Madame and her two black-
dressed daughters in whose house we were now living, and who
were themselves putting up in the adjoining farmhouse, which
belonged to them.
I said that they had done all the digging in the garden. I should
make one reservation. All the potato-patch had been dug by our
servants, with the assistance of Gray, the cook. Nor did they do it in
gratitude to Madame, as, doubtless, ideal Tommies would have
done. A quarter of it was done by Lewis, for carelessness in losing
my valise; nearly half by the joint effort of the whole crew for a
thoroughly dirty turn-out on commanding officer’s inspection; and
the rest for various other defalcations! We never told Madame the
reasons for their welcome help; and I am quite sure they never did!
“I dare say,” said Edwards; “but, as the phrase goes, ‘What are you
going to do abaht it?’ Here’s Jim. Old Muskett’s going to send me a
nag at five, so I’m going out after tea. Will you be in to tea?”
“Don’t know.”
“Come on, old boy,” I said, as I reached the bottom of this little
valley; and trotting up the other side, and through a ride in the
wood, I came out on the edge of the Valley of the Somme. I then
skirted the south side of the wood until I reached a secluded corner
with a view across the valley: here I dismounted, fastened Jim to a
tree, loosened his girths, and left him pulling greedily at the grass at
his feet. Then I threw myself down on the grass to dream.
In the front line “A” Company had had several killed and wounded,
and I had had to lend them half my bombers; as I had placed two
men on one post, a canister had burst quite a long way off, but the
men cowered down into the trench. I cursed them as hard as I
could, and then I saw that in the post were the two former
occupants lying dead, killed half an hour ago where they lay, and
where I was placing my two men. I stopped my curses, and inwardly
directed them against myself. And there I had to leave these fellows,
looking after me and thinking, “He’s going back to his dug-out.” Ah!
no, they knew me better than to think like that. Yet I had to go
back, leaving them there. I should never forget that awful weight of
responsibility that suddenly seemed visualised before me. Could I
not see their scared faces peering at me, even as now I seemed to
smell the scent of pear-drops with which the trench was permeated,
the Germans having sent over a few lachrymatory shells along with
the others that night?
Ah! Why was I living all this over again, just when I had come away
to get free of all this awhile, and dream? I had come out to enjoy
the sunshine and the peace, just as Jim was enjoying the grass
behind me. I listened. There was a slight jingle of the bit now and
again, and a creaking of leather, and always that drawing sound,
with an occasional purr, as the grass was torn up. I could not help
looking round at last. “You pig,” I said; but my tone did not
altogether disapprove of complacent piggishness.
In front of me lay the blue water of the Somme Canal, and the pools
between it and the river; long parallel rows of pale green poplars
stretched along either bank of the canal; and at my feet, half hidden
by the slope of the ground, lay the sleepy little village of Etinehem.
There was a Sunday afternoon slumber over everything. Was it
Sunday? I thought for a moment. No, it was Thursday, and to-
morrow we went “in” again. I deliberately switched my thoughts
away from the trenches, and they flew to the events of the morning.
I could see my fellows lying, so keen—I might almost say so happy—
blazing away on the range. One I remembered especially. Private
Benjamin, a boy with a delicate eager face, who came out with the
last draft: he came from a village close up to Snowdon; he was
shooting badly, and very concerned about it. I lay down beside him
and showed him how to squeeze the trigger, gradually, ever so
gradually. Oh! these boys! Responsibility. Responsibility.
“This is no good,” I said to myself at last, and untied Jim and rode
again. I went down into the valley, and along the green track
between an avenue of poplars south of the canal until at last I came
to Sailly-Laurette, and so back and in to Morlancourt from the south-
west. It was six o’clock by the time I stooped my head under the
gateway into our garden, and for the last hour or so I had almost
forgotten war at last.
“Hullo,” was the greeting I received from Owen. “There’s no tea left.”
“Seven o’clock!”
Then Jim Potter came in, and Comic Cuts faded into insignificance.
“Well, Jim,” we said, “how are things going? When’s the war going to
end?”
The joint was not quite ready, Edwards explained to me, drawing me
aside a minute; would old Jim mind? The idea of old Jim minding
being quite absurd, we decided on having a cooked joint a quarter of
an hour hence, rather than a semi-raw one now; and we told Jim
our decision. It seemed to suit him exactly, as he had had tea late.
There never was such an unruffled fellow as he; had we wanted to
begin before the time appointed, he would have been ravenous. So
he continued the description of his adventures on leave. Meanwhile I
rescued Comic Cuts from the hands of Paul, and despatched them,
duly initialled, by the trusty Davies to “C” Company. Just as I had
done so the sergeant-major appeared at the door.
“The fellows are still talking about this ‘rest,’ sir. No news about that,
I suppose?” said the sergeant-major.
“Oh, yes; I should think so,” said the quartermaster. “Any time next
year.”
After soup, sausages and beef, and rice-pudding and tinned fruit,
came Watson’s special dish—cheese au gratin on toast. This was a
glutinous concoction, and a little went a long way. Then followed
café au lait made in the teapot, which was the signal for cigarettes
to be lit up, and chairs to be moved a little to allow of a comfortable
expansion of legs. Owen proposed sitting out in the summer-house,
but on going outside reported that it was a little too chilly. So we
remained where we were.
Edwards was talking of Amiens: he had been there for the day
yesterday, and incidentally discovered that there was a cathedral
there.
“You had a good time at the Army School, didn’t you?” asked Jim.
Jim Potter and Edwards had got it up; it had been an al fresco affair,
and the night had been ideally warm for it. Edwards had trained a
Welsh choir with some success. Several outsiders had contributed,
the star of the evening being Basil Hallam, the well-known music-
hall artist, whose dainty manner, reminding one of the art of Vesta
Tilley, and impeccable evening clothes had produced an
unforgettably bizarre effect in the middle of such an audience and
within sound of the guns. He was well known to most of the men as
“the bloke that sits up in the sausage.” For any fine day, coming out
of trenches or going in, you could see high suspended the
“sausage,” whose home and “base” was between Treux and
Mericourt, and whose occupant and eye was Basil Hallam. And so
the “sausage bloke” was received enthusiastically at our concert.
“A dog barking in Fricourt,” said old Jim, warming up. “‘A dog
barking in Fricourt.’ What’s that—Corps stuff? I never read the thing;
good Lord, no! That’s what it is to have a Staff—‘A dog barking in
Fricourt!’”
“The Corps officer didn’t hear it,” said I. “It was some battalion
intelligence officer that was such a fool as to report it.”
“Fool?” said old Jim. “I’d like to meet the fellow. He’s the first fellow
I’ve ever met yet who has a just appreciation of the brain capacity of
the Staff. You or I might have thought of reporting a dog’s mew, or
roar, or bellow; but a dog’s bark we should have thought of no
interest whatever to the—er—fellows up there, you know, who plan
our destinies.” And he gave an obsequious flick of his hand to an
imaginary person too high up to see him at all.
“He’s a good fellow,” he repeated, “that intelligence officer. Ought to
get a D.S.O.”
Old Jim had two South African medals, a D.C.M. and a D.S.O.
“The Staff,” he went on, with the greatest contempt he could put
into his voice. “I saw three of them in a car to-day. I stood to
attention: saluted. A young fellow waved his hand, you know;
graciously accepted my salute, you know, and passed on leaning
back in his limousin. The ‘Brains of the British Army,’ I thought. Pah!”
“Push!” he said. “Of course there will be a push. The Staff must have
something to show for themselves. ‘Shove ’em in,’ they say; ‘rather a
bigger front than last time.’ Strategy? Oh, no! That’s out of date, you
know. Five-mile front—frontal attack. Get a few hundred thousand
mown down, and then discover the Boche has got a second line. The
Staff. Pah!!” And no more would he say.
Then Clark came in, and the Manchester Stokes gun officer. Clark
immediately joined Owen in a duet on “Florrie.” Then we went
through the whole gamut of popular songs, with appropriate actions
and stamping of feet upon the floor. Meanwhile the table was
cleared, only the whiskey and Perrier remaining. Soon there were
cries of “Napoleon—Napoleon,” and Owen, who bears a remarkable
resemblance to that great personage, posed tragically again and
again amid great applause. And then, in natural sequence, I, as “Bill,
the man wot won the Battle of Waterloo,” attacked him with every
species of trench-mortar I could lay hands on, my head swathed in a
remarkable turban of Daily Mail. At last I drove him into a corner
behind a table, and bombarded him relentlessly with oranges until
he capitulated! All the time Edwards had been in fear and trembling
for the safety of his gramophone.
At length peace was signed, and we grew quiet again beneath the
soothing strains of the gramophone, until at last Jim Potter said he
must really go. Everyone reminding everyone else that breakfast was
at seven, we broke up the party, and Owen, Paul, Jim Potter and I
departed together. But anyone who knows the psychology of
conviviality will understand that we had first to pay a visit to a
neighbouring Mess for one last whiskey-and-soda before turning in.
I could not help thinking of the jollity of the last few hours, the
humour, the apparently spontaneous outburst of good spirits; and
most of all I thought of old Jim, the mainspring somehow of it all.
And again I saw the picture of the concert a few nights ago, the
bright lights of the stage, the crowds of our fellows, all their bodies
and spirits for the moment relaxed, good-natured, happy, as they
stood laughing in the warm night air. And lastly I thought again of
Private Benjamin, that refined eager face, that rather delicate body,
and that warm hand as I placed mine over his, squeezing the trigger.
He was no more than a child really, a simple-minded child of Wales.
Somehow it was more terrible that these young boys should see this
war, than for the older men. Yet were we not all children wondering,
wondering, wondering?... Yes, we were like children faced by a wild
beast. “Sometimes I dislike you almost,” I thought; “your dulness,
your coarseness, your lack of romance, your unattractiveness. Yet
that is only physical. You, I love really. Oh, the dear, dear world!”
“Come and have a look,” I called to Owen, who had just entered the
dug-out. I could see him standing with his back to the candlelight
reading a letter or something.
“Yes, I hardly noticed it; our guns make such a row. By Jove, it’s
magnificent.”
We gazed fascinated for a long time, and then went into the dug-out
where Edwards and Paul were snoring rhythmically. I read for half an
hour, but the dug-out was stuffy, and the smell of sand-bags and the
flickering of the candle annoyed me for some reason or other.
Somehow “Derelicts” by W. J. Locke failed to grip my attention.
Owing to our bombardment, there were no working-parties, in case
the Germans should take it into their head to retaliate vigorously.
But at present there was no sign of that.
I went outside again, and walked along Park Lane until I came to the
Lewis-gun position just this side of the corner of Watling Street. The
sentry was standing up, with his elbows on the ground level (there
was no parapet) gazing alert and interested at the continuous flicker
of our shells bursting along the enemy’s trenches. Lance-Corporal
Allan looked out of the dug-out, and, seeing me, came out and
stood by us. And together we watched, all three of us, in silence.
Overhead was the continual griding, screeching, whistling of the
shells as they passed over, without pause or cessation; behind was a
chain of gun-flickers the other side of the ridge; and in front was
another chain of flashes, and a succession of bump, bump, bumps,
as the shells burst relentlessly in the German trenches. And where
we stood, under the noisy arch, was a steady calm.
“This is all right, sir,” said Lance-Corporal Allan. He was the N.C.O. in
charge of this Lewis-gun team.
For always, through the last four months, the artillery had been
more or less confined to so many shells a day. The officers used to
tell us they had any amount of ammunition, yet no sooner were they
given a free hand to retaliate as much as we wanted, than an order
came cancelling this privilege. To-night at any rate there was no
curtailment.
Corporal Allan smiled, and as he did so the flashes lit up his face. He
was quite a boy, only eighteen, I believe, but an excellent N.C.O. He
had a very beautiful though sensuous face that used to remind me
sometimes of the “Satyr” of Praxiteles. His only fault was an
inclination to sulkiness at times, which was perhaps due to a little
streak of vanity. It was no wonder the maidens of Morlancourt made
eyes at him, and a little girl who lived next door to the Lewis-
gunner’s billet was said to have lost her heart long ago. To-night I
felt a pang as I saw him smile.
“We’ll see,” I said. “Anyway it’s going to be a good show giving the
Boche these sort of pleasant dreams. Better than those one-minute
stunts.”
I went back and visited the other gun position, and spent a few
minutes there also. At last I turned in reluctantly. I went out again at
half-past eleven, and still the shells were screaming over. It seemed
the token of an irresistible power. And there was no reply at all now
from the German lines.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebooknice.com